public void AddAxis(int num, bool inverted, List <string> l) { if (num < 0) { return; } string axisName = InputAxis.FromIntBool(num, inverted); l.Add(axisName); }
void RemoveAxis(int num, bool inverted) { if (num < 0) { return; } string name = InputAxis.FromIntBool(num, inverted); if (script.AxesUsedCurrent.Contains(name)) { script.AxesUsedCurrent.Remove(name); } else if (script.AxesUsedOther.Contains(name)) { script.AxesUsedOther.Remove(name); } }
void AxisStatus(int num, bool inverted, bool error) { if (num == -1) { EditorGUILayout.LabelField("Unassigned!", unassignedStyle); } else { if (error) { EditorGUILayout.LabelField(InputAxis.FromIntBool(num, inverted), errorStyle); } else { EditorGUILayout.LabelField(InputAxis.FromIntBool(num, inverted), setStyle); } } }
void SetLastInput() { for (int i = 1; i < 29; i++) { string axis = "Axis" + i; float v = Input.GetAxis(axis); if (v > 0.5f && v < 0.98f) { string name = InputAxis.FromIntBool(i, false); if (AxesUsedCurrent.Contains(name)) { return; } if (AxesUsedOther.Contains(name)) { Debug.LogWarning("Warning: " + name + " is already assigned to the other Controller. It cannot appear as 'last Axis used!'"); return; } lastAxisUsed = InputAxis.FromIntBool(i, false); lastAxisNegative = false; } if (v < -0.5f && v > -0.98f) { string name = InputAxis.FromIntBool(i, true); if (AxesUsedCurrent.Contains(name)) { return; } if (AxesUsedOther.Contains(name)) { Debug.LogWarning(name + " is already assigned to the other Controller. It cannot appear as 'last Axis used!'"); return; } lastAxisUsed = InputAxis.FromIntBool(i, true); lastAxisNegative = true; } } for (int i = 0; i < 20; i++) // Checks only the main joystick buttons { string name = "JoystickButton" + i; KeyCode key = (KeyCode)System.Enum.Parse(typeof(KeyCode), name); if (Input.GetKeyDown(key)) { if (KeysUsedCurrent.Contains(i)) { return; } if (KeysUsedOther.Contains(i)) { Debug.LogWarning("The JoystickButton" + i + " is already assigned to the other Controller. It cannot appear as 'last Button pressed!'"); return; } lastButtonPressed = i; } } }
bool LastAxisIsUnused(int num, bool inverted) { string lastAxisUsed = script.lastAxisUsed; bool unused = true; bool originalIsInverted; string[] parts = lastAxisUsed.Split(); string invertedName; string normalName; string oppositeName; if (parts.Length > 1) // if there is '(inverted)' before the axis name { invertedName = lastAxisUsed; normalName = parts[1]; oppositeName = normalName; originalIsInverted = true; } else { normalName = lastAxisUsed; invertedName = "(inverted) " + lastAxisUsed; oppositeName = invertedName; originalIsInverted = false; } if (num > -1) { string current = InputAxis.FromIntBool(num, inverted); if (current == oppositeName) { return(true); } // assigning the same axis but (un)inverted is possible. } // TODO: Avoid having 12 if statements for creating specific error messages. // Check current controller if (script.AxesUsedCurrent.Contains(normalName)) { if (originalIsInverted) { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to current Controller in inverted variant."); } else { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to current Controller."); } } else if (script.AxesUsedCurrent.Contains(invertedName)) { if (originalIsInverted) { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to current Controller."); } else { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to current Controller in un-inverted variant."); } } // Check other controller if (script.AxesUsedOther.Contains(normalName)) { if (originalIsInverted) { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to other Controller in inverted variant."); } else { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to other Controller."); } } else if (script.AxesUsedOther.Contains(invertedName)) { if (originalIsInverted) { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to other Controller."); } else { unused = false; Debug.LogError(lastAxisUsed + " is already assigned to other Controller in un-inverted variant."); } } return(unused); }