diff --git a/Nez.Portable/Input/Virtual/VirtualAxis.cs b/Nez.Portable/Input/Virtual/VirtualAxis.cs old mode 100644 new mode 100755 index 14e6acfc6..497655d7d --- a/Nez.Portable/Input/Virtual/VirtualAxis.cs +++ b/Nez.Portable/Input/Virtual/VirtualAxis.cs @@ -10,6 +10,9 @@ namespace Nez public class VirtualAxis : VirtualInput { public List Nodes = new List(); + + float _simulatedValue; + int _simulationStep; public float Value { @@ -22,7 +25,7 @@ public float Value return val; } - return 0; + return _simulatedValue; } } @@ -38,10 +41,28 @@ public VirtualAxis(params Node[] nodes) } + public void Simulate(float value) + { + _simulatedValue = value; + _simulationStep = 1; + } + + public override void Update() { for (var i = 0; i < Nodes.Count; i++) Nodes[i].Update(); + + switch (_simulationStep) + { + case 1: + _simulationStep++; + break; + case 2: + _simulatedValue = 0; + _simulationStep = 0; + break; + } } @@ -256,4 +277,4 @@ public override void Update() #endregion } -} \ No newline at end of file +} diff --git a/Nez.Portable/Input/Virtual/VirtualButton.cs b/Nez.Portable/Input/Virtual/VirtualButton.cs old mode 100644 new mode 100755 index 414ddbc38..39ed27949 --- a/Nez.Portable/Input/Virtual/VirtualButton.cs +++ b/Nez.Portable/Input/Virtual/VirtualButton.cs @@ -21,6 +21,11 @@ public class VirtualButton : VirtualInput float _repeatCounter; bool _willRepeat; + bool _simulatePress; + bool _simulateDown; + bool _simulateRelease; + int _simulationStep; + public VirtualButton(float bufferTime) { @@ -62,6 +67,12 @@ public void SetRepeat(float firstRepeatTime, float multiRepeatTime) } + public void Simulate() + { + _simulationStep = 1; + } + + public override void Update() { _bufferCounter -= Time.UnscaledDeltaTime; @@ -103,6 +114,29 @@ public override void Update() } } } + + switch (_simulationStep) + { + case 1: + _simulatePress = true; + _simulateDown = true; + _simulationStep++; + break; + case 2: + _simulatePress = false; + _simulationStep++; + break; + case 3: + _simulateDown = false; + _simulateRelease = true; + _simulationStep++; + break; + case 4: + _simulateRelease = false; + _simulationStep = -1; + break; + } + } @@ -114,7 +148,7 @@ public bool IsDown if (node.IsDown) return true; - return false; + return _simulateDown; } } @@ -130,7 +164,7 @@ public bool IsPressed if (node.IsPressed) return true; - return false; + return _simulatePress; } } @@ -143,7 +177,7 @@ public bool IsReleased if (node.IsReleased) return true; - return false; + return _simulateRelease; } } @@ -576,4 +610,4 @@ public class MouseSecondExtendedButton : Node #endregion } -} \ No newline at end of file +} diff --git a/Nez.Portable/Input/Virtual/VirtualIntegerAxis.cs b/Nez.Portable/Input/Virtual/VirtualIntegerAxis.cs old mode 100644 new mode 100755 index 3ab8722d0..34d088065 --- a/Nez.Portable/Input/Virtual/VirtualIntegerAxis.cs +++ b/Nez.Portable/Input/Virtual/VirtualIntegerAxis.cs @@ -12,6 +12,9 @@ namespace Nez public class VirtualIntegerAxis : VirtualInput { public List Nodes = new List(); + + int _simulatedValue; + int _simulationStep; public int Value { @@ -24,7 +27,7 @@ public int Value return Math.Sign(val); } - return 0; + return _simulatedValue; } } @@ -40,10 +43,28 @@ public VirtualIntegerAxis(params VirtualAxis.Node[] nodes) } + public void Simulate(int value) + { + _simulatedValue = value; + _simulationStep = 1; + } + + public override void Update() { for (var i = 0; i < Nodes.Count; i++) Nodes[i].Update(); + + switch (_simulationStep) + { + case 1: + _simulationStep++; + break; + case 2: + _simulatedValue = 0; + _simulationStep = 0; + break; + } } diff --git a/Nez.Portable/Input/Virtual/VirtualJoystick.cs b/Nez.Portable/Input/Virtual/VirtualJoystick.cs old mode 100644 new mode 100755 index 8b58f778e..7ec9ff5a7 --- a/Nez.Portable/Input/Virtual/VirtualJoystick.cs +++ b/Nez.Portable/Input/Virtual/VirtualJoystick.cs @@ -13,6 +13,9 @@ public class VirtualJoystick : VirtualInput public List Nodes = new List(); public bool Normalized; + Vector2 _simulatedValue = Vector2.Zero; + int _simulationStep; + public Vector2 Value { get @@ -28,7 +31,7 @@ public Vector2 Value } } - return Vector2.Zero; + return _simulatedValue; } } @@ -46,10 +49,29 @@ public VirtualJoystick(bool normalized, params Node[] nodes) : base() } + public void Simulate(Vector2 value) + { + _simulatedValue = value; + _simulationStep = 1; + } + + public override void Update() { for (int i = 0; i < Nodes.Count; i++) Nodes[i].Update(); + + + switch (_simulationStep) + { + case 1: + _simulationStep++; + break; + case 2: + _simulatedValue = Vector2.Zero; + _simulationStep = 0; + break; + } }