-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using UnityEngine; | ||
|
||
namespace InputSystem | ||
{ | ||
// A float axis control. | ||
// Can optionally be configured to perform normalization. | ||
public class AxisControl : InputControl<float> | ||
{ | ||
// These can be added as processors but they are so common that we | ||
// build the functionality right into AxisControl. | ||
public bool clamp; // If true, force clamping to [min..max] | ||
public float clampMin; | ||
public float clampMax; | ||
public bool invert; | ||
|
||
private float Preprocess(float value) | ||
{ | ||
if (invert) | ||
value *= -1.0f; | ||
if (clamp) | ||
value = Mathf.Clamp(value, clampMin, clampMax); | ||
return value; | ||
} | ||
|
||
public AxisControl(string name) | ||
: base(name) | ||
{ | ||
stateBlock.sizeInBits = sizeof(float)*8; | ||
} | ||
|
||
public override float value | ||
{ | ||
get | ||
{ | ||
unsafe | ||
{ | ||
var buffer = (byte*) currentStatePtr; | ||
return Process(Preprocess(*((float*) &buffer[stateBlock.byteOffset]))); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
|
||
namespace InputSystem | ||
{ | ||
////REVIEW: shouldn't this still have a float value type? | ||
public class ButtonControl : InputControl<bool> | ||
{ | ||
public ButtonControl(string name) | ||
: base(name) | ||
{ | ||
} | ||
|
||
protected unsafe bool GetValue(IntPtr statePtr) | ||
{ | ||
var buffer = (byte*) statePtr; | ||
return Process((buffer[stateBlock.byteOffset] & (1 << (int)stateBlock.bitOffset)) == (byte) (1 << (int)stateBlock.bitOffset)); | ||
} | ||
|
||
public override bool value | ||
{ | ||
get { return GetValue(currentStatePtr); } | ||
} | ||
|
||
public bool wasPressedThisFrame | ||
{ | ||
get { return value != GetValue(previousStatePtr); } | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace InputSystem | ||
{ | ||
public class DiscreteControl : InputControl<int> | ||
{ | ||
public DiscreteControl(string name) | ||
: base(name) | ||
{ | ||
stateBlock.sizeInBits = sizeof(int)*8; | ||
} | ||
|
||
public override int value | ||
{ | ||
get | ||
{ | ||
unsafe | ||
{ | ||
var buffer = (byte*) currentStatePtr; | ||
return Process(*((int*) &buffer[stateBlock.byteOffset])); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using UnityEngine; | ||
|
||
namespace InputSystem | ||
{ | ||
// A control made up of four discrete, directional buttons. Forms a vector | ||
// but can also be addressed as individual buttons. | ||
public class DpadControl : InputControl<Vector2> | ||
{ | ||
public enum ButtonBits | ||
{ | ||
Up, | ||
Down, | ||
Left, | ||
Right, | ||
} | ||
|
||
[InputControl(bit = (int)ButtonBits.Up)] | ||
public ButtonControl up { get; private set; } | ||
[InputControl(bit = (int)ButtonBits.Down)] | ||
public ButtonControl down { get; private set; } | ||
[InputControl(bit = (int)ButtonBits.Left)] | ||
public ButtonControl left { get; private set; } | ||
[InputControl(bit = (int)ButtonBits.Right)] | ||
public ButtonControl right { get; private set; } | ||
|
||
public DpadControl(string name) | ||
: base(name) | ||
{ | ||
} | ||
|
||
public override Vector2 value | ||
{ | ||
get | ||
{ | ||
unsafe | ||
{ | ||
var upValue = up.value ? 1.0f : 0.0f; | ||
var downValue = down.value ? -1.0f : 0.0f; | ||
var leftValue = left.value ? -1.0f : 0.0f; | ||
var rightValue = right.value ? 1.0f : 0.0f; | ||
|
||
return Process(new Vector2(leftValue + rightValue, upValue + downValue)); | ||
} | ||
} | ||
} | ||
|
||
protected override void FinishSetup(InputControlSetup setup) | ||
{ | ||
up = setup.GetControl<ButtonControl>(this, "up"); | ||
down = setup.GetControl<ButtonControl>(this, "down"); | ||
left = setup.GetControl<ButtonControl>(this, "left"); | ||
right = setup.GetControl<ButtonControl>(this, "right"); | ||
base.FinishSetup(setup); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.