public AxisDelegate CreateAxisDelegate(Joystick joystick = Joystick.All) { switch (this.Type) { case InputType.Unknown: return(null); case InputType.Joystick: { switch (this.Mode) { case InputMode.Axis: { if (float.IsNaN(this.DeadZone)) { return(SPInputFactory.CreateAxisDelegate((SPInputId)this.Value, (SPInputId)this.AltValue, joystick)); } else { return(SPInputFactory.CreateAxisDelegate((SPInputId)this.Value, joystick, this.AltValue != 0)); } } case InputMode.Trigger: return(SPInputFactory.CreateTriggerDelegate((SPInputId)this.Value, joystick, (AxleValueConsideration)this.AltValue)); case InputMode.LongTrigger: return(SPInputFactory.CreateLongTriggerDelegate((SPInputId)this.Value, joystick)); case InputMode.Button: return(SPInputFactory.CreateTriggerDelegate(SPInputFactory.CreateButtonDelegate((SPInputId)this.Value, joystick))); case InputMode.AxleButton: return(SPInputFactory.CreateTriggerDelegate(SPInputFactory.CreateAxleButtonDelegate((SPInputId)this.Value, (AxleValueConsideration)this.AltValue, joystick, this.DeadZone))); } } break; case InputType.Keyboard: { switch (this.Mode) { case InputMode.Axis: return(SPInputFactory.CreateAxisDelegate((KeyCode)this.Value, (KeyCode)this.AltValue)); case InputMode.Trigger: case InputMode.LongTrigger: case InputMode.Button: case InputMode.AxleButton: return(SPInputFactory.CreateTriggerDelegate((KeyCode)this.Value)); } } break; case InputType.Custom: { if (_axisDelegate is AxisDelegateFactory) { return((_axisDelegate as AxisDelegateFactory)(joystick)); } else if (_axisDelegate is AxisDelegate) { return(_axisDelegate as AxisDelegate); } else if (_buttonDelegate is ButtonDelegateFactory) { return(SPInputFactory.CreateTriggerDelegate((_buttonDelegate as ButtonDelegateFactory)(joystick))); } else if (_buttonDelegate is ButtonDelegate) { return(SPInputFactory.CreateTriggerDelegate(_buttonDelegate as ButtonDelegate)); } else { return(null); } } } return(null); }
public float PollAxis(Joystick joystick = Joystick.All) { switch (this.Type) { case InputType.Unknown: return(0f); case InputType.Joystick: { switch (this.Mode) { case InputMode.Axis: { if (float.IsNaN(this.DeadZone)) { var d = SPInputFactory.CreateAxisDelegate((SPInputId)this.Value, (SPInputId)this.AltValue, joystick); return(d != null?d() : 0f); } else { //return SPInputFactory.CreateAxisDelegate((SPInputId)this.Value, joystick, this.AltValue != 0); float v = SPInputDirect.GetAxis((SPInputId)this.Value, joystick); if (this.AltValue != 0) { v = -v; } return(v); } } case InputMode.Trigger: { var d = SPInputFactory.CreateTriggerDelegate((SPInputId)this.Value, joystick, (AxleValueConsideration)this.AltValue); return(d != null?d() : 0f); } case InputMode.LongTrigger: { var d = SPInputFactory.CreateLongTriggerDelegate((SPInputId)this.Value, joystick); return(d != null?d() : 0f); } case InputMode.Button: //return SPInputFactory.CreateTriggerDelegate(SPInputFactory.CreateButtonDelegate((SPInputId)this.Value, joystick)); return(SPInputDirect.GetButton((SPInputId)this.Value, joystick) ? 1f : 0f); case InputMode.AxleButton: { var d = SPInputFactory.CreateTriggerDelegate(SPInputFactory.CreateAxleButtonDelegate((SPInputId)this.Value, (AxleValueConsideration)this.AltValue, joystick, this.DeadZone)); return(d != null?d() : 0f); } } } break; case InputType.Keyboard: { switch (this.Mode) { case InputMode.Axis: { //return SPInputFactory.CreateAxisDelegate((KeyCode)this.Value, (KeyCode)this.AltValue); if (Input.GetKey((KeyCode)this.Value)) { return(1f); } else if (Input.GetKey((KeyCode)this.AltValue)) { return(-1f); } else { return(0f); } } case InputMode.Trigger: case InputMode.LongTrigger: case InputMode.Button: case InputMode.AxleButton: //return SPInputFactory.CreateTriggerDelegate((KeyCode)this.Value); return(Input.GetKey((KeyCode)this.Value) ? 1f : 0f); } } break; case InputType.Custom: { if (_axisDelegate is AxisDelegateFactory) { var d = (_axisDelegate as AxisDelegateFactory)(joystick); return(d != null?d() : 0f); } else if (_axisDelegate is AxisDelegate) { var d = _axisDelegate as AxisDelegate; return(d != null?d() : 0f); } else if (_buttonDelegate is ButtonDelegateFactory) { var d = SPInputFactory.CreateTriggerDelegate((_buttonDelegate as ButtonDelegateFactory)(joystick)); return(d != null?d() : 0f); } else if (_buttonDelegate is ButtonDelegate) { var d = SPInputFactory.CreateTriggerDelegate(_buttonDelegate as ButtonDelegate); return(d != null?d() : 0f); } else { return(0f); } } } return(0f); }