|
|
|
|
|
|
private static string kPersistentBtn = "Debug Persistent"; |
|
|
|
private static string kDPadVertical = "Debug Vertical"; |
|
|
|
private static string kDPadHorizontal = "Debug Horizontal"; |
|
|
|
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2, kDebugPreviousBtn, kDebugNextBtn, kValidateBtn, kPersistentBtn, kDPadVertical, kDPadHorizontal }; |
|
|
|
|
|
|
|
|
|
|
|
public enum DebugAction |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bool m_Valid = false; |
|
|
|
DebugActionManager() |
|
|
|
void RegisterActions() |
|
|
|
m_Valid = Debugging.CheckRequiredInputButtonMapping(m_RequiredInputButtons); |
|
|
|
|
|
|
|
m_DebugActions = new DebugActionDesc[(int)DebugAction.DebugActionCount]; |
|
|
|
m_DebugActionStates = new DebugActionState[(int)DebugAction.DebugActionCount]; |
|
|
|
|
|
|
|
|
|
|
persistent.buttonTriggerList.Add(new[] { kPersistentBtn }); |
|
|
|
persistent.repeatMode = DebugActionRepeatMode.Never; |
|
|
|
AddAction(DebugAction.MakePersistent, persistent); |
|
|
|
|
|
|
|
AddAction(DebugAction.MoveVertical, new DebugActionDesc { axisTrigger = kDPadVertical, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f } ); |
|
|
|
AddAction(DebugAction.MoveHorizontal, new DebugActionDesc { axisTrigger = kDPadHorizontal, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f } ); |
|
|
|
|
|
|
|
AddAction(DebugAction.MoveVertical, new DebugActionDesc { axisTrigger = kDPadVertical, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f }); |
|
|
|
AddAction(DebugAction.MoveHorizontal, new DebugActionDesc { axisTrigger = kDPadHorizontal, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f }); |
|
|
|
} |
|
|
|
|
|
|
|
DebugActionManager() |
|
|
|
{ |
|
|
|
RegisterInputs(); |
|
|
|
RegisterActions(); |
|
|
|
} |
|
|
|
|
|
|
|
void AddAction(DebugAction action, DebugActionDesc desc) |
|
|
|
|
|
|
|
|
|
|
public void Update() |
|
|
|
{ |
|
|
|
if (!m_Valid) |
|
|
|
return; |
|
|
|
|
|
|
|
for(int actionIndex = 0 ; actionIndex < m_DebugActions.Length ; ++actionIndex) |
|
|
|
{ |
|
|
|
UpdateAction(actionIndex); |
|
|
|
|
|
|
{ |
|
|
|
return m_DebugActionStates[(int)action].actionState; |
|
|
|
} |
|
|
|
|
|
|
|
void RegisterInputs() |
|
|
|
{ |
|
|
|
#if UNITY_EDITOR
|
|
|
|
// Grab reference to input manager
|
|
|
|
UnityEditor.EditorApplication.ExecuteMenuItem("Edit/Project Settings/Input"); |
|
|
|
var inputManager = UnityEditor.Selection.activeObject; |
|
|
|
|
|
|
|
// Wrap in serialized object
|
|
|
|
var soInputManager = new UnityEditor.SerializedObject(inputManager); |
|
|
|
var spAxes = soInputManager.FindProperty("m_Axes"); |
|
|
|
|
|
|
|
// Add new bindings
|
|
|
|
new InputManagerEntry { name = kEnableDebugBtn1, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "left ctrl", altBtnPositive = "joystick button 8" }.WriteEntry(spAxes); |
|
|
|
new InputManagerEntry { name = kEnableDebugBtn2, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "backspace", altBtnPositive = "joystick button 9" }.WriteEntry(spAxes); |
|
|
|
|
|
|
|
new InputManagerEntry { name = kDebugNextBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "page down", altBtnPositive = "joystick button 5" }.WriteEntry(spAxes); |
|
|
|
new InputManagerEntry { name = kDebugPreviousBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "page up", altBtnPositive = "joystick button 4" }.WriteEntry(spAxes); |
|
|
|
|
|
|
|
new InputManagerEntry { name = kDPadHorizontal, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "right", btnNegative = "left", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f }.WriteEntry(spAxes); |
|
|
|
new InputManagerEntry { name = kDPadHorizontal, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Sixth, btnPositive = "right", btnNegative = "left", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f }.WriteEntry(spAxes); |
|
|
|
new InputManagerEntry { name = kDPadVertical, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "up", btnNegative = "down", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f }.WriteEntry(spAxes); |
|
|
|
new InputManagerEntry { name = kDPadVertical, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Seventh, btnPositive = "up", btnNegative = "down", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f }.WriteEntry(spAxes); |
|
|
|
|
|
|
|
new InputManagerEntry { name = kValidateBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "return", altBtnPositive = "joystick button 0" }.WriteEntry(spAxes); |
|
|
|
new InputManagerEntry { name = kPersistentBtn, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "right shift", altBtnPositive = "joystick button 2" }.WriteEntry(spAxes); |
|
|
|
|
|
|
|
// Commit
|
|
|
|
soInputManager.ApplyModifiedProperties(); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
class InputManagerEntry |
|
|
|
{ |
|
|
|
public enum Kind { KeyOrButton, Mouse, Axis } |
|
|
|
public enum Axis { X, Y, Third, Fourth, Fifth, Sixth, Seventh, Eigth } |
|
|
|
public enum Joy { All, First, Second } |
|
|
|
|
|
|
|
public string name; |
|
|
|
public string desc; |
|
|
|
public string btnNegative; |
|
|
|
public string btnPositive; |
|
|
|
public string altBtnNegative; |
|
|
|
public string altBtnPositive; |
|
|
|
public float gravity; |
|
|
|
public float deadZone; |
|
|
|
public float sensitivity; |
|
|
|
public bool snap; |
|
|
|
public bool invert; |
|
|
|
public Kind kind; |
|
|
|
public Axis axis; |
|
|
|
public Joy joystick; |
|
|
|
|
|
|
|
bool InputAlreadyRegistered(string name, Kind kind, UnityEditor.SerializedProperty spAxes) |
|
|
|
{ |
|
|
|
for (var i = 0; i < spAxes.arraySize; ++i ) |
|
|
|
{ |
|
|
|
var spAxis = spAxes.GetArrayElementAtIndex(i); |
|
|
|
var axisName = spAxis.FindPropertyRelative("m_Name").stringValue; |
|
|
|
var kindValue = spAxis.FindPropertyRelative("type").intValue; |
|
|
|
if (axisName == name && (int)kind == kindValue) |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public void WriteEntry(UnityEditor.SerializedProperty spAxes) |
|
|
|
{ |
|
|
|
if(InputAlreadyRegistered(name, kind, spAxes)) |
|
|
|
return; |
|
|
|
|
|
|
|
spAxes.InsertArrayElementAtIndex(spAxes.arraySize); |
|
|
|
var spAxis = spAxes.GetArrayElementAtIndex(spAxes.arraySize - 1); |
|
|
|
spAxis.FindPropertyRelative("m_Name").stringValue = name; |
|
|
|
spAxis.FindPropertyRelative("descriptiveName").stringValue = desc; |
|
|
|
spAxis.FindPropertyRelative("negativeButton").stringValue = btnNegative; |
|
|
|
spAxis.FindPropertyRelative("altNegativeButton").stringValue = altBtnNegative; |
|
|
|
spAxis.FindPropertyRelative("positiveButton").stringValue = btnPositive; |
|
|
|
spAxis.FindPropertyRelative("altPositiveButton").stringValue = altBtnPositive; |
|
|
|
spAxis.FindPropertyRelative("gravity").floatValue = gravity; |
|
|
|
spAxis.FindPropertyRelative("dead").floatValue = deadZone; |
|
|
|
spAxis.FindPropertyRelative("sensitivity").floatValue = sensitivity; |
|
|
|
spAxis.FindPropertyRelative("snap").boolValue = snap; |
|
|
|
spAxis.FindPropertyRelative("invert").boolValue = invert; |
|
|
|
spAxis.FindPropertyRelative("type").intValue = (int)kind; |
|
|
|
spAxis.FindPropertyRelative("axis").intValue = (int)axis; |
|
|
|
spAxis.FindPropertyRelative("joyNum").intValue = (int)joystick; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif
|
|
|
|
} |
|
|
|
} |