4 using System.Collections.Generic;
10 public enum ControlsAction : byte
46 public static float Power
48 get {
return _instance._power; }
56 get {
return _instance._direction; }
64 get {
return _instance._smoothCadence; }
67 public AnimationCurve PowerCurve;
79 Dictionary<int, bool> _actionPrevStates;
80 Dictionary<int, bool> _actionStates;
81 Dictionary<int, float> _actionHoldTimes;
82 Dictionary<int, List<IActionInfoProvider>> _actionInfoProviders;
92 _instance._actionInfoProviders[(int)action].Insert(0, actionInfoProvider);
102 _instance._actionInfoProviders[(int)action].Remove(actionInfoProvider);
111 _instance._smoothCadence = cadence;
115 float power = cadence / _health.CadenceCap;
124 power = _instance.PowerCurve.Evaluate(power);
126 _instance._power = power;
138 _instance._direction = direction.normalized;
149 if (state && !_instance._actionStates[(
int)action])
151 else if (!state && _instance._actionStates[(
int)action])
154 _instance._actionStates[(int)action] = state;
162 var providers = _instance._actionInfoProviders[(int)action];
164 if (providers.Count != 0)
165 return providers[0].GetActionCaption(action);
175 var providers = _instance._actionInfoProviders[(int)action];
177 if (providers.Count != 0)
178 return providers[0].IsActionEnabled(action);
188 return _instance._actionStates[(int)action];
196 return _instance._actionStates[(int)action] && !_instance._actionPrevStates[(
int)action];
204 return !_instance._actionStates[(int)action] && _instance._actionPrevStates[(
int)action];
212 return _instance._actionHoldTimes[(int)action];
221 _instance._actionHoldTimes[(int)action] = 0;
228 _actionStates =
new Dictionary<int, bool>();
229 _actionPrevStates =
new Dictionary<int, bool>();
230 _actionHoldTimes =
new Dictionary<int, float>();
231 _actionInfoProviders =
new Dictionary<int, List<IActionInfoProvider>>();
233 foreach (var action
in Enum.GetValues(typeof(ControlsAction)))
235 _actionStates[(int)(ControlsAction)action] = false;
236 _actionPrevStates[(
int)(ControlsAction)action] = false;
237 _actionHoldTimes[(
int)(ControlsAction)action] = 0f;
244 foreach (var action
in _actionStates.Keys)
246 _actionPrevStates[(int)action] = _actionStates[action];
248 if (_actionStates[(
int)action])
249 _actionHoldTimes[(
int)action] += Time.deltaTime;
251 _actionHoldTimes[(int)action] = 0;
261 void OnConnectedToWorldServer()
263 _health = Game.LocalPlayerProfile.Health;
266 void OnDisconnectedFromWorldServer()
static float Power
Returns an abstract power value in the range [0 ... 1].
static bool GetAction(ControlsAction action)
Returns the current state of an action.
static void UnregisterActionInfoProvider(ControlsAction action, IActionInfoProvider actionInfoProvider)
Unregister an action info provider.
static void InjectActionState(ControlsAction action, bool state)
Injections an action state.
float MinPower
The value below which power is simply considered zero.
static float GetActionHoldTime(ControlsAction action)
Returns the amount of time the given action has been held down.
static float RawCadence
Returns the raw pedaling cadence for logging use or other study reasons.
static void InjectSmoothCadence(float cadence)
Injects a power value.
static void InjectDirection(Vector3 direction)
Injects a direction. Call this from a device script.
DisconnectedFromWorldServerHandler DisconnectedFromWorldServer
Event fired when the game client is disconnected from the world server.
static bool GetActionDown(ControlsAction action)
Checks if the given action has just been pressed down.
static Vector3 Direction
Returns a normalized, abstract direction. Could also be zero.
ConnectedToWorldServerHandler ConnectedToWorldServer
Event fired when the game client successfully connects to the world server.
static string GetActionCaption(ControlsAction action)
Returns the current caption for a given action.
Interface for classes which provide information for an action.
static bool IsActionEnabled(ControlsAction action)
Checks if a given action is enabled.
static GameClient Instance
Gets the sole instance of the game client.
Class for managing study-related game components.
static void RegisterActionInfoProvider(ControlsAction action, IActionInfoProvider actionInfoProvider)
Register an action info provider.
static bool GetActionUp(ControlsAction action)
Checks if the given action has just been released.
static void LogEvent(Enum eventType, params object[] args)
Log a game event.
Controls class. Allows for controls queries and controls injection from devices.
static void ResetHoldTime(ControlsAction action)
Resets the Hold Time of an action. Used to "consume" a held input, such as the 3 second hold for quit...