public AxisMap(AxisMapData _axisMapData, InputController _inputController) : base(_inputController) { axisMapData = _axisMapData; if (axisMapData.sensitivity == 0) { axisMapData.sensitivity = 1; } if (Name == null) { axisMapData.name = ""; } MapMessage = axisMapData.negativeAxisName == null ? PositiveAxisName : "(-)" + NegativeAxisName + " | (+)" + PositiveAxisName; UpdateAxisStrings(); }
public IEnumerator TestForInputCore() { AxisMapData originalData = axisMapData; MapMessage = PositiveAxisMessage + " Ready"; yield return(new WaitForSeconds(2f)); float positiveValue = 0; float startTime = Time.time; yield return(new WaitWhile(() => { MapMessage = PositiveAxisMessage + Mathf.RoundToInt(InputCheckTime - (Time.time - startTime)).ToString(); axisMapData.positiveAxisName = Input.DetectAxes(controller, out positiveValue); if (axisMapData.positiveAxisName == "") { axisMapData.positiveAxisName = Input.DetectButton(controller); if (axisMapData.positiveAxisName != "") { axisMapData.isVirtual = true; positiveValue = 1; } } axisMapData.isPositiveAxisInverted = positiveValue < 0; return axisMapData.positiveAxisName == "" && Time.time - startTime < InputCheckTime; })); if (axisMapData.positiveAxisName == "") { axisMapData = originalData; } originalData = axisMapData; if (!axisMapData.is0To1Axis) { MapMessage = NegativeAxisMessage + " Ready"; yield return(new WaitForSeconds(2f)); float negativeValue = 0; startTime = Time.time; yield return(new WaitWhile(() => { MapMessage = NegativeAxisMessage + Mathf.RoundToInt(InputCheckTime - (Time.time - startTime)).ToString(); if (axisMapData.isVirtual) { axisMapData.negativeAxisName = Input.DetectButton(controller); negativeValue = -1; } else { axisMapData.negativeAxisName = Input.DetectAxes(controller, out negativeValue); axisMapData.isNegativeAxisInverted = negativeValue > 0; } return (axisMapData.negativeAxisName == "" || axisMapData.negativeAxisName == null) && Time.time - startTime < InputCheckTime; })); if (axisMapData.negativeAxisName == "" || axisMapData.negativeAxisName == axisMapData.positiveAxisName) { axisMapData = originalData; axisMapData.negativeAxisName = null; } } UpdateAxisStrings(); MapMessage = axisMapData.negativeAxisName == null ? (axisMapData.isPositiveAxisInverted ? ("Inverted ") : "") + PositiveAxisName : "(-)" + (axisMapData.isNegativeAxisInverted ? ("Inverted ") : "") + NegativeAxisName + " | (+)" + (axisMapData.isPositiveAxisInverted ? ("Inverted ") : "") + PositiveAxisName; }
private void AxisMapsGUI(AxisMap axisMap, RuntimePlatform newRuntimePlatform) { int baseIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = baseIndentLevel + 1; EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth = EditorGUIUtility.currentViewWidth / 3; bool changeToVirtual = EditorGUILayout.Popup("Axis Type", axisMap.IsVirtual ? 1 : 0, new string[] { "Direct", "Virtual" }) == 1; if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(target, ((axisMap.IsVirtual ? "Changed to Real Axis for" : "Changed to Virtual Axis") + axisMap.Name)); AxisMapData axisMapData = axisMap.AxisMapData; axisMapData.isVirtual = changeToVirtual; axisMapData.negativeAxisName = axisMapData.isVirtual ? "0" : ""; axisMapData.positiveAxisName = axisMapData.isVirtual ? "3" : "0"; typeof(AxisMap).GetField("axisMapData", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(axisMap, axisMapData); EditorUtility.SetDirty(target); } if (axisMap.IsVirtual) { EditorGUI.BeginChangeCheck(); EditorGUI.indentLevel = baseIndentLevel + 1; bool isInverted = EditorGUILayout.Toggle("Invert Axis", axisMap.IsInverted); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(target, ("Changed Inversion of " + axisMap.Name)); AxisMapData axisMapData = axisMap.AxisMapData; axisMapData.isInverted = isInverted; typeof(AxisMap).GetField("axisMapData", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(axisMap, axisMapData); EditorUtility.SetDirty(target); } } RuntimePlatform filter = filterForPlatform ?newRuntimePlatform: RuntimePlatform.PS4; Dictionary <string, string> joyAxes = axisMap.IsVirtual ? JoyPlatformMaps.GetButtonsForPlatform(filter) : JoyPlatformMaps.GetAxisForPlatform(filter); joyAxes.Add("", "Not Active"); string[] joyAxisArrayNames = joyAxes.Select(x => x.Key + " | " + x.Value).OrderBy(x => x).ToArray(); EditorGUI.indentLevel = baseIndentLevel + 1; EditorGUI.BeginChangeCheck(); int newBut = EditorGUILayout.Popup("Negative Axis", joyAxes.Keys.OrderBy(x => x).ToList().IndexOf(axisMap.AxisMapData.negativeAxisName), (joyAxisArrayNames).ToArray()); EditorGUI.indentLevel = baseIndentLevel + 2; if (axisMap.NegativeAxisName == "" || axisMap.AxisMapData.isVirtual) { GUI.enabled = false; } bool isNegativeAxisInverted = EditorGUILayout.Toggle("Is Inverted", axisMap.AxisMapData.isNegativeAxisInverted); GUI.enabled = true; if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(target, ("Changed mapping of " + axisMap.Name)); string val = joyAxes.Keys.ToArray().OrderBy(x => x).ToArray()[newBut]; AxisMapData axisMapData = axisMap.AxisMapData; axisMapData.negativeAxisName = val; axisMapData.isNegativeAxisInverted = isNegativeAxisInverted && !axisMapData.isVirtual; typeof(AxisMap).GetField("axisMapData", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(axisMap, axisMapData); EditorUtility.SetDirty(target); } joyAxes.Remove(""); joyAxisArrayNames = joyAxes.Select(x => x.Key + " | " + x.Value).OrderBy(x => x).ToArray(); EditorGUI.indentLevel = baseIndentLevel + 1; EditorGUI.BeginChangeCheck(); newBut = EditorGUILayout.Popup("Positive Axis", joyAxes.Keys.OrderBy(x => x).ToList().IndexOf(axisMap.AxisMapData.positiveAxisName), joyAxisArrayNames); EditorGUILayout.BeginHorizontal(); EditorGUI.indentLevel = baseIndentLevel + 2; GUI.enabled = !axisMap.AxisMapData.isVirtual; bool isPostiveAxisInverted = EditorGUILayout.Toggle("Is Inverted", (axisMap.AxisMapData.negativeAxisName == "" && !axisMap.AxisMapData.isVirtual ? axisMap.AxisMapData.isInverted : axisMap.AxisMapData.isPositiveAxisInverted), GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); GUI.enabled = true; if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(target, ("Changed mapping of " + axisMap.Name)); string val = joyAxes.Keys.ToArray().OrderBy(x => x).ToArray()[newBut]; AxisMapData axisMapData = axisMap.AxisMapData; axisMapData.positiveAxisName = val; if (axisMapData.negativeAxisName == "") { axisMapData.isInverted = isPostiveAxisInverted; axisMapData.isPositiveAxisInverted = false; } else { axisMapData.isPositiveAxisInverted = isPostiveAxisInverted && !axisMapData.isVirtual; } typeof(AxisMap).GetField("axisMapData", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(axisMap, axisMapData); EditorUtility.SetDirty(target); } EditorGUI.indentLevel = baseIndentLevel; }