Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Hydrogen.Peripherals.Input Class Reference
+ Inheritance diagram for Hydrogen.Peripherals.Input:

Public Member Functions

bool AddAction (String name, InputAction action)
 
bool RemoveAction (String name, bool alsoRemoveControls)
 
bool AddControl (String controlName, String actionName)
 
void RemoveControl (String controlName)
 
void ClearControls ()
 Clears all controls. More...
 
List< KeyValuePair< string,
string > > 
GetControls ()
 Gets the controls. More...
 
bool SetControls (List< KeyValuePair< string, string >> controlScheme)
 Set the controls from a List<KeyValuePair<string, string>> More...
 

Protected Member Functions

virtual void Awake ()
 
virtual void Update ()
 

Detailed Description

Definition at line 47 of file Input.cs.

Member Function Documentation

bool Hydrogen.Peripherals.Input.AddAction ( String  name,
InputAction  action 
)

Definition at line 67 of file Input.cs.

68  {
69  if (!_actions.ContainsKey (name)) {
70  _actions.Add (name, action);
71  return true;
72  }
73  return false;
74  }
bool Hydrogen.Peripherals.Input.AddControl ( String  controlName,
String  actionName 
)

Definition at line 99 of file Input.cs.

100  {
101  InputAction action;
102 
103  if (!_actions.TryGetValue (actionName, out action)) {
104  return false;
105  }
106 
107 
108  InputControlBase control = InputControlBase.CreateControl (controlName, action);
109  control.ActionName = actionName;
110 
111  if (control != null) {
112  _controls.Add (control);
113  return true;
114  }
115  return false;
116  }
delegate void InputAction(InputEvent evt, float value, float time)
virtual void Hydrogen.Peripherals.Input.Awake ( )
protectedvirtual

Reimplemented in hInput.

Definition at line 52 of file Input.cs.

53  {
54  if (_controls == null)
55  _controls = new List<InputControlBase> ();
56  if (_actions == null)
57  _actions = new Dictionary<String, InputAction> ();
58  }
void Hydrogen.Peripherals.Input.ClearControls ( )

Clears all controls.

Definition at line 136 of file Input.cs.

137  {
138  _controls.Clear ();
139  }
List<KeyValuePair<string, string> > Hydrogen.Peripherals.Input.GetControls ( )

Gets the controls.

Returns
The controls as a ist<KeyValuePair<string, string>>

Definition at line 145 of file Input.cs.

146  {
147  var controlList = new List<KeyValuePair<string, string>> ();
148 
149  for (int x = 0; x < _controls.Count; x++) {
150  controlList.Add (new KeyValuePair<string, string> (_controls [x].ActionName, _controls [x].Name));
151  }
152 
153  return controlList;
154  }
bool Hydrogen.Peripherals.Input.RemoveAction ( String  name,
bool  alsoRemoveControls 
)

Definition at line 76 of file Input.cs.

77  {
78  InputAction action;
79  if (_actions.TryGetValue (name, out action)) {
80  if (alsoRemoveControls) {
81  bool hasMore = true;
82  while (hasMore) {
83  hasMore = false;
84  foreach (InputControlBase control in _controls) {
85  if (control.Action == action) {
86  _controls.Remove (control);
87  hasMore = true;
88  break;
89  }
90  }
91  }
92  }
93  _actions.Remove (name);
94  return true;
95  }
96  return false;
97  }
delegate void InputAction(InputEvent evt, float value, float time)
void Hydrogen.Peripherals.Input.RemoveControl ( String  controlName)

Definition at line 118 of file Input.cs.

119  {
120  bool hasMore = true;
121  while (hasMore) {
122  hasMore = false;
123  foreach (InputControlBase control in _controls) {
124  if (control.Name == controlName) {
125  _controls.Remove (control);
126  hasMore = true;
127  break;
128  }
129  }
130  }
131  }
bool Hydrogen.Peripherals.Input.SetControls ( List< KeyValuePair< string, string >>  controlScheme)

Set the controls from a List<KeyValuePair<string, string>>

This is useful for loading saved settings, specifically using Hydrogen.Serialization.INI

Returns
true, if controls were set, false otherwise.
Parameters
controlSchemeControl Scheme.

Definition at line 164 of file Input.cs.

165  {
166  bool check = true;
167 
168  for (int x = 0; x < controlScheme.Count; x++) {
169  // Reverse because we're assuming this came from a serialized version of the config
170  check &= AddControl (controlScheme [x].Value, controlScheme [x].Key);
171  }
172 
173  return check;
174  }
bool AddControl(String controlName, String actionName)
Definition: Input.cs:99
virtual void Hydrogen.Peripherals.Input.Update ( )
protectedvirtual

Definition at line 60 of file Input.cs.

61  {
62  foreach (InputControlBase control in _controls) {
63  control.Capture ();
64  }
65  }