Ejemplo n.º 1
0
 /// <summary>
 /// Sets the given <see cref="AxisMapping"/> to be a <see cref="AxisMapping.AxisType.KeyWrapper"/>
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="key1"></param>
 /// <param name="key2"></param>
 private static void MakeKeyWrapper(AxisMapping mapping, KeyCode key1 = KeyCode.None, KeyCode key2 = KeyCode.None)
 {
     mapping.Type = AxisMapping.AxisType.KeyWrapper;
     mapping.Key1 = key1;
     mapping.Min  = key1 != KeyCode.None ? -1 : 0;
     mapping.Key2 = key2;
     mapping.Max  = key2 != KeyCode.None ? 1 : 0;
 }
Ejemplo n.º 2
0
 public CarbonController()
 {
     for (int i = 0; i < Buttons.Length; i++)
     {
         Buttons[i] = new ButtonMapping();
     }
     for (int i = 0; i < Axes.Length; i++)
     {
         Axes[i] = new AxisMapping();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Copy all values from the parameter.
 /// </summary>
 /// <param name="other"></param>
 public void CopyFrom(AxisMapping other)
 {
     Axis        = other.Axis;
     Alternative = other.Alternative;
     Invert      = other.Invert;
     Type        = other.Type;
     Min         = other.Min;
     Max         = other.Max;
     Key1        = other.Key1;
     Key2        = other.Key2;
 }
Ejemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            GUI.changed = false;
            CarbonController mapping = (CarbonController)target;

            EditorGUI.BeginChangeCheck();
            string regex = EditorGUILayout.TextField(new GUIContent("RegEx", "Regular expression used to match joystick names."), mapping.RegEx);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(mapping, "Changed Gamepad RegEx");
                mapping.RegEx = regex;
            }

            EditorGUI.BeginChangeCheck();
            int priority = EditorGUILayout.IntField(new GUIContent("Priority", "Lower values are checked earlier."), mapping.Priority);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(mapping, "Changed Gamepad Priority");
                mapping.Priority = priority;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Platform");
            EditorGUI.BeginChangeCheck();
            CPlatform platform = (CPlatform)EditorGUILayout.EnumMaskField(mapping.Platform);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(mapping, "Changed Gamepad Platform");
                mapping.Platform = platform;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUI.BeginChangeCheck();
            bool useOnce = EditorGUILayout.Toggle(new GUIContent("Use Once", "Whether this mapping should only be used for one joystick."), mapping.UseOnce);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(mapping, "Changed Gamepad Use Once");
                mapping.UseOnce = useOnce;
            }

            showButtons = EditorGUILayout.Foldout(showButtons, "Buttons");
            if (showButtons)
            {
                EditorGUILayout.BeginVertical();
                for (int i = 0; i < CarbonController.ButtonCount; i++)
                {
                    ButtonMapping btn = mapping.Buttons[i];
                    ButtonMapping tmp = new ButtonMapping(btn);
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(((CButton)i).ToString(), GUILayout.MaxWidth(50f));
                    tmp.Type = (ButtonMapping.ButtonType)EditorGUILayout.EnumPopup(btn.Type, GUILayout.MaxWidth(100f));
                    if (btn.Type == ButtonMapping.ButtonType.Wrapper)
                    {
                        tmp.Key = (KeyCode)EditorGUILayout.EnumPopup(btn.Key, GUILayout.MaxWidth(100f));
                    }
                    else
                    {
                        tmp.Button = Mathf.Clamp(EditorGUILayout.IntField(btn.Button, GUILayout.MaxWidth(100f)), 0, 19);
                    }
                    EditorGUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(mapping, "Changed Button Mapping");
                        btn.CopyFrom(tmp); // copy back
                    }
                }
                EditorGUILayout.EndVertical();
            }

            showAxes = EditorGUILayout.Foldout(showAxes, "Axes");
            if (showAxes)
            {
                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", GUILayout.MaxWidth(50f));
                EditorGUILayout.LabelField("Axis", GUILayout.MaxWidth(70f));
                EditorGUILayout.LabelField("Invert", GUILayout.MaxWidth(40f));
                EditorGUILayout.LabelField("Type", GUILayout.MaxWidth(80f));
                EditorGUILayout.EndHorizontal();
                for (int i = 0; i < CarbonController.AxisCount; i++)
                {
                    AxisMapping axis = mapping.Axes[i];
                    AxisMapping tmp  = new AxisMapping(axis);
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(((CAxis)i).ToString(), GUILayout.MaxWidth(50f));
                    if (axis.Type == AxisMapping.AxisType.KeyWrapper || axis.Type == AxisMapping.AxisType.ButtonWrapper2)
                    {
                        EditorGUILayout.LabelField("", GUILayout.MaxWidth(80f));
                    }
                    else if (axis.Type == AxisMapping.AxisType.ButtonWrapper)
                    {
                        tmp.Axis = Mathf.Clamp(EditorGUILayout.IntField(axis.Axis, GUILayout.MaxWidth(80f)), 0, CarbonController.JoystickButtonCount - 1);
                    }
                    else
                    {
                        tmp.Axis = Mathf.Clamp(EditorGUILayout.IntField(axis.Axis, GUILayout.MaxWidth(80f)), 0, CarbonController.InputAxisCount - 1);
                    }
                    tmp.Invert = EditorGUILayout.Toggle(axis.Invert, GUILayout.MaxWidth(20f));
                    tmp.Type   = (AxisMapping.AxisType)EditorGUILayout.EnumPopup(axis.Type, GUILayout.MaxWidth(100f));
                    EditorGUILayout.EndHorizontal();

                    switch (axis.Type)
                    {
                    case AxisMapping.AxisType.KeyWrapper:
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Negative", GUILayout.MaxWidth(60f));
                        tmp.Key1 = (KeyCode)EditorGUILayout.EnumPopup(axis.Key1, GUILayout.MaxWidth(80f));
                        EditorGUILayout.LabelField("Positive", GUILayout.MaxWidth(60f));
                        tmp.Key2 = (KeyCode)EditorGUILayout.EnumPopup(axis.Key2, GUILayout.MaxWidth(80f));
                        EditorGUILayout.EndHorizontal();
                        break;

                    case AxisMapping.AxisType.ButtonWrapper:
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Released", GUILayout.MaxWidth(60f));
                        tmp.Min = EditorGUILayout.FloatField(axis.Min, GUILayout.MaxWidth(40f));
                        EditorGUILayout.LabelField("Pressed", GUILayout.MaxWidth(60f));
                        tmp.Max = EditorGUILayout.FloatField(axis.Max, GUILayout.MaxWidth(40f));
                        EditorGUILayout.EndHorizontal();
                        break;

                    case AxisMapping.AxisType.ButtonWrapper2:
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Negative", GUILayout.MaxWidth(60f));
                        tmp.Axis = Mathf.Clamp(EditorGUILayout.IntField(axis.Axis, GUILayout.MaxWidth(40f)), 0, CarbonController.JoystickButtonCount - 1);
                        EditorGUILayout.LabelField("Positive", GUILayout.MaxWidth(60f));
                        tmp.Alternative = Mathf.Clamp(EditorGUILayout.IntField(axis.Alternative, GUILayout.MaxWidth(40f)), 0, CarbonController.JoystickButtonCount - 1);
                        EditorGUILayout.EndHorizontal();
                        break;

                    case AxisMapping.AxisType.Clamped:
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Min", GUILayout.MaxWidth(40f));
                        tmp.Min = EditorGUILayout.FloatField(axis.Min, GUILayout.MaxWidth(40f));
                        EditorGUILayout.LabelField("Max", GUILayout.MaxWidth(40f));
                        tmp.Max = EditorGUILayout.FloatField(axis.Max, GUILayout.MaxWidth(40f));
                        EditorGUILayout.EndHorizontal();
                        break;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(mapping, "Changed Axis Mapping");
                        axis.CopyFrom(tmp); // copy back
                    }
                }
                EditorGUILayout.EndVertical();
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the value of the virtual axis of player <paramref name="id"/> identified by the <paramref name="axis"/> parameter;
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual float GetAxis(CAxis axis, int id)
        {
            AxisMapping mapping = Axes[(int)axis];
            float       result  = 0;

            switch (mapping.Type)
            {
            case AxisMapping.AxisType.Default:
                result = Input.GetAxis(AxisNames[id, mapping.Axis]);
                break;

            case AxisMapping.AxisType.ButtonWrapper:
                result = Input.GetKey(KeyCode.JoystickButton0 + id * JoystickButtonCount + mapping.Axis) ? mapping.Max : mapping.Min;
                break;

            case AxisMapping.AxisType.KeyWrapper:
                bool key1 = Input.GetKey(mapping.Key1);
                bool key2 = Input.GetKey(mapping.Key2);
                if (key1 && !key2)
                {
                    result = -1;
                }
                else if (!key1 && key2)
                {
                    result = 1;
                }
                else
                {
                    result = 0;
                }
                break;

            case AxisMapping.AxisType.Clamped:
                result = Mathf.Clamp(Input.GetAxis(AxisNames[id, mapping.Axis]), mapping.Min, mapping.Max);
                break;

            case AxisMapping.AxisType.ButtonWrapper2:
                key1 = Input.GetKey(KeyCode.JoystickButton0 + id * JoystickButtonCount + mapping.Axis);
                key2 = Input.GetKey(KeyCode.JoystickButton0 + id * JoystickButtonCount + mapping.Alternative);
                if (key1 && !key2)
                {
                    result = -1;
                }
                else if (!key1 && key2)
                {
                    result = 1;
                }
                else
                {
                    result = 0;
                }
                break;

            case AxisMapping.AxisType.TriggerLimiter:
                result = (Input.GetAxis(AxisNames[id, mapping.Axis]) + 1f) / 2f;
                break;
            }
            if (mapping.Invert)
            {
                return(-result);
            }
            return(result);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="other"></param>
 public AxisMapping(AxisMapping other)
 {
     CopyFrom(other);
 }