コード例 #1
0
        public InputMappingNew AddMap(InputMappingNew.InputType mappingType, string newName = "")
        {
            var parent = manager.transform.Find("InputMappings");

            if (!parent)
            {
                new GameObject("InputMappings").transform.parent = manager.transform;
                return(AddMap(mappingType, newName));
            }
            InputMappingNew tempMapping = null;

            switch (mappingType)
            {
            case InputMappingNew.InputType.Button:
                tempMapping = (InputMappingNew)Undo.AddComponent(parent.gameObject, typeof(ButtonMap));
                break;

            case InputMappingNew.InputType.Trigger_Grab:
                tempMapping = (InputMappingNew)Undo.AddComponent(parent.gameObject, typeof(FloatMap));
                break;

            case InputMappingNew.InputType.Joystick_Trackpad:
                tempMapping = (InputMappingNew)Undo.AddComponent(parent.gameObject, typeof(Vector2Map));
                break;
            }

            if (!newName.Equals(""))
            {
                tempMapping.mapName = newName;
            }

            manager.RefreshInputMappings();
            return(tempMapping);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            SerializedProperty mapName    = serializedObject.FindProperty("mapName");
            SerializedProperty buttonMap  = serializedObject.FindProperty("buttonMap");
            SerializedProperty value      = serializedObject.FindProperty("value");
            SerializedProperty activeArea = serializedObject.FindProperty("activeArea");

            SerializedProperty Activated    = serializedObject.FindProperty("Activated");
            SerializedProperty DeActivated  = serializedObject.FindProperty("Deactivated");
            SerializedProperty StateChanged = serializedObject.FindProperty("StateChanged");


            mapName.stringValue = EditorGUILayout.TextField(mapName.stringValue);

            EditorGUILayout.BeginHorizontal();
            InputMappingNew.InputType typeSwitch = (InputMappingNew.InputType)EditorGUILayout.EnumPopup(InputMappingNew.InputType.Button);
            buttonMap.enumValueIndex =
                (int)(FloatMap.FloatInput)EditorGUILayout.EnumPopup((ButtonMap.Buttons)buttonMap.enumValueIndex);
            EditorGUILayout.EndHorizontal();


            bool splitActivation = Screen.width > 480;

            Utils.EditorUtils.SplitPropertyView(Activated, DeActivated, splitActivation);

            EditorGUILayout.PropertyField(StateChanged);


            serializedObject.ApplyModifiedProperties();

            if (typeSwitch != InputMappingNew.InputType.Button)
            {
                InputMappingNew.SwitchType((ButtonMap)target, typeSwitch);
            }
        }
コード例 #3
0
 public void RemoveMap(InputMappingNew targetMap)
 {
     Undo.SetCurrentGroupName("Removed Input Map");
     Undo.DestroyObjectImmediate(targetMap);
     Undo.RecordObject(manager, "Removed Input Map");
     manager.RefreshInputMappings();
     Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
     return;
 }
コード例 #4
0
        bool ShowRemoveButton(InputMappingNew mapping)
        {
            if (GUILayout.Button("-", EditorStyles.miniButtonLeft, miniButtonWidth))
            {
                RemoveMap(mapping);
                return(true);
            }

            return(false);
        }
コード例 #5
0
        public void OnEnable()
        {
            string parName = transform.name.Substring(0, 1);

            if (parName == "L")
            {
                handedness = hands.Left;
            }
            else if (parName == "R")
            {
                handedness = hands.Right;
            }
            else
            {
                Debug.Log("Parent Hand Unsure");
            }

            if (!grabMap && inputMappings != null && inputMappings.Length > 0)
            {
                foreach (var inputMap in inputMappings)
                {
                    if (inputMap.name.Contains("Grab"))
                    {
                        grabMap = inputMap;
                        break;
                    }
                }
            }

            if (interactor != null && grabMap != null)
            {
                grabMap.TryGetComponent(out FloatMap floatMap);
                grabMap.TryGetComponent(out ButtonMap buttonMap);

                if (floatMap != null)
                {
                    floatMap.Activated.AddListener(interactor.NotifyTryGrabbed);
                    floatMap.Deactivated.AddListener(interactor.NotifyTryUnGrabbed);
                }
                else if (buttonMap != null)
                {
                    buttonMap.Activated.AddListener(interactor.NotifyTryGrabbed);
                    buttonMap.Deactivated.AddListener(interactor.NotifyTryUnGrabbed);
                }
            }
        }
コード例 #6
0
        public override void OnInspectorGUI()
        {
            SerializedProperty mapName     = serializedObject.FindProperty("mapName");
            SerializedProperty vector2Map  = serializedObject.FindProperty("vector2Map");
            SerializedProperty activeRange = serializedObject.FindProperty("activeRange");

            SerializedProperty MovedX       = serializedObject.FindProperty("MovedX");
            SerializedProperty MovedY       = serializedObject.FindProperty("MovedY");
            SerializedProperty StateChanged = serializedObject.FindProperty("StateChanged");

            SerializedProperty Touched   = serializedObject.FindProperty("Touched");
            SerializedProperty UnTouched = serializedObject.FindProperty("UnTouched");

            SerializedProperty Clicked   = serializedObject.FindProperty("Clicked");
            SerializedProperty UnClicked = serializedObject.FindProperty("UnClicked");

            mapName.stringValue = EditorGUILayout.TextField(mapName.stringValue);

            EditorGUILayout.BeginHorizontal();
            InputMappingNew.InputType typeSwitch = (InputMappingNew.InputType)EditorGUILayout.EnumPopup(InputMappingNew.InputType.Joystick_Trackpad);
            vector2Map.enumValueIndex =
                (int)(FloatMap.FloatInput)EditorGUILayout.EnumPopup((Vector2Map.Axis2D)vector2Map.enumValueIndex);
            EditorGUILayout.EndHorizontal();


            bool splitActivation = Screen.width > 480;

            Utils.EditorUtils.SplitPropertyView(MovedX, MovedY, splitActivation);


            EditorGUILayout.PropertyField(StateChanged);

            EditorGUILayout.Space();

            Utils.EditorUtils.SplitPropertyView(Touched, UnTouched, splitActivation);
            Utils.EditorUtils.SplitPropertyView(Clicked, UnClicked, splitActivation);

            serializedObject.ApplyModifiedProperties();

            if (typeSwitch != InputMappingNew.InputType.Joystick_Trackpad)
            {
                InputMappingNew.SwitchType((Vector2Map)target, typeSwitch);
            }
        }
コード例 #7
0
        public override void OnInspectorGUI()
        {
            SerializedProperty mapName     = serializedObject.FindProperty("mapName");
            SerializedProperty floatMap    = serializedObject.FindProperty("floatMap");
            SerializedProperty activeRange = serializedObject.FindProperty("activeRange");

            SerializedProperty Activated    = serializedObject.FindProperty("Activated");
            SerializedProperty Deactivated  = serializedObject.FindProperty("Deactivated");
            SerializedProperty StateChanged = serializedObject.FindProperty("StateChanged");


            mapName.stringValue = EditorGUILayout.TextField(mapName.stringValue);

            EditorGUILayout.BeginHorizontal();
            InputMappingNew.InputType typeSwitch = (InputMappingNew.InputType)EditorGUILayout.EnumPopup(InputMappingNew.InputType.Trigger_Grab);

            floatMap.enumValueIndex =
                (int)(FloatMap.FloatInput)EditorGUILayout.EnumPopup((FloatMap.FloatInput)floatMap.enumValueIndex);
            EditorGUILayout.EndHorizontal();

            var tempRange = new FloatRange(activeRange.vector2Value);

            Utils.EditorUtils.ShowRangeArea(ref tempRange);
            activeRange.vector2Value = tempRange.ToVector2();
            bool splitActivation = Screen.width > 480;

            Utils.EditorUtils.SplitPropertyView(Activated, Deactivated, splitActivation);

            EditorGUILayout.PropertyField(StateChanged);


            serializedObject.ApplyModifiedProperties();

            if (typeSwitch != InputMappingNew.InputType.Trigger_Grab)
            {
                InputMappingNew.SwitchType((FloatMap)target, typeSwitch);
            }
        }
コード例 #8
0
        public static InputMappingNew SwitchType(InputMappingNew originalMap, InputType type)
        {
            int originalIndex = -1;

            var maps = originalMap.gameObject.GetComponents <InputMappingNew>();

            for (int i = 0; i < maps.Length; i++)
            {
                if (maps[i].Equals(originalMap))
                {
                    originalIndex = i;
                }
            }

            if (originalIndex == -1)
            {
                Debug.LogError($"Map on {originalMap.gameObject} didnt have {originalMap.mapName}", originalMap);
                return(null);
            }

            InputMappingNew newMap = null;

            switch (type)
            {
            case InputType.Button:
                ButtonMap newButtonMap = (ButtonMap)UnityEditor.Undo.AddComponent(originalMap.gameObject, typeof(ButtonMap));

                //originalMap.TryGetComponent(out FloatMap floatMap);
                //if(floatMap != null)
                //{


                //	int listeners = floatMap.Activated.GetPersistentEventCount();
                //	for (int i = 0; i < listeners; i++)
                //	{
                //	string methodName = floatMap.Activated.GetPersistentMethodName(i);
                //	string finalName = floatMap.Activated.GetPersistentMethodName(i);
                //		Utils.EventUtillity.TransferPersistentCalls(floatMap, newButtonMap, "Activated", "Activated");
                //	}

                //}
                newMap = newButtonMap;
                break;

            case InputType.Trigger_Grab:
                FloatMap newFloatMap = (FloatMap)UnityEditor.Undo.AddComponent(originalMap.gameObject, typeof(FloatMap));

                //originalMap.TryGetComponent(out ButtonMap buttonMap);
                //if (buttonMap != null)
                //{


                //	int listeners = buttonMap.Activated.GetPersistentEventCount();
                //	for (int i = 0; i < listeners; i++)
                //	{
                //		string methodName = buttonMap.Activated.GetPersistentMethodName(i);
                //		string finalName = buttonMap.Activated.GetPersistentMethodName(i);
                //		Debug.Log(Utils.EventUtillity.TransferPersistentCalls(buttonMap, newFloatMap, "Activated", "Activated"));
                //	}

                //}

                newMap = newFloatMap;
                break;

            case InputType.Joystick_Trackpad:
                Vector2Map newVec2Map = (Vector2Map)UnityEditor.Undo.AddComponent(originalMap.gameObject, typeof(Vector2Map));
                newMap = newVec2Map;
                break;
            }
            for (int i = 0; i < maps.Length - originalIndex; i++)
            {
                UnityEditorInternal.ComponentUtility.MoveComponentUp(newMap);
            }

            newMap.mapName = originalMap.mapName;

            DestroyImmediate(originalMap);
            return(newMap);
        }