Ejemplo n.º 1
0
        public void ButtonMapsGUI(ButtonMap buttonMap, RuntimePlatform runtimePlatform)
        {
            RuntimePlatform             filter     = filterForPlatform ? runtimePlatform : RuntimePlatform.PS4;
            Dictionary <string, string> joyButtons = JoyPlatformMaps.GetButtonsForPlatform(filter);

            string[] joyButtonArrayNames = joyButtons.Select(x => x.Key + "  |  " + x.Value).OrderBy(x => x).ToArray();
            EditorGUI.BeginChangeCheck();
            int newBut = EditorGUILayout.Popup(joyButtons.Keys.OrderBy(x => x).ToList().IndexOf(buttonMap.ButtonMapData.buttonMapName), joyButtonArrayNames);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(target, ("Changed mapping of " + buttonMap.Name));
                string        val           = joyButtons.Keys.ToArray().OrderBy(x => x).ToArray()[newBut];
                ButtonMapData buttonMapData = buttonMap.ButtonMapData;
                buttonMapData.buttonMapName = val;
                typeof(ButtonMap).GetField("buttonMapData", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).SetValue(buttonMap, buttonMapData);
                EditorUtility.SetDirty(target);
            }
        }
Ejemplo n.º 2
0
        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;
        }