public static bool InitializePrefix(InputManager_Base __instance)
        {
            Debug.Log("Extended Quickslots - Prefix()");
            InputAction        inputAction;
            List <InputAction> actions_Copy;
            Traverse           inputActionTrav;

            for (var x = 0; x < ExtendedQuickslots.numSlots; ++x)
            {
                // Add an action to the QuickSlot category (see 'Rewired_actions.txt')
                __instance.userData.AddAction(2);

                // This is how we have to get the action we just added
                actions_Copy = __instance.userData.GetActions_Copy();
                inputAction  = actions_Copy[actions_Copy.Count - 1];

                //Debug.Log("ExtendedQuickslots - InitializePatch() before edit inputAction:\r\n\tname: " + inputAction.name + "\r\n\tdescriptiveName: " + inputAction.descriptiveName + "\r\n\tuserAssignable: " + inputAction.userAssignable + "\r\n\tbehaviorId: " + inputAction.behaviorId);
                // Set the action specific data
                // We use 12 as the base index to avoid conflicts with other game data.
                // This is done to code around an issue with how there's more quickslots
                // due to controllers, so we start with 12 rather than 9 to avoid issues.
                // We'll just change what the options menu shows though, so this internal name
                // doesn't really matter.
                inputActionTrav = Traverse.Create(inputAction);
                string name = string.Format("QS_Instant{0}", x + 12);
                inputActionTrav.Property("name").SetValue(name);
                inputActionTrav.Property("descriptiveName").SetValue("Action0");
                inputActionTrav.Property("userAssignable").SetValue(true);
                inputActionTrav.Property("behaviorId").SetValue(0);

                Debug.Log("ExtendedQuickslots - InitializePatch() inputAction:\r\n\tname: " + inputAction.name + "\r\n\tdescriptiveName: " + inputAction.descriptiveName + "\r\n\tuserAssignable: " + inputAction.userAssignable + "\r\n\tbehaviorId: " + inputAction.behaviorId);
            }

            __instance.userData.AddAction(4); //Sit emote
            __instance.userData.AddAction(4); //alternate idle
            actions_Copy = __instance.userData.GetActions_Copy();

            inputAction     = actions_Copy[actions_Copy.Count - 2];
            inputActionTrav = Traverse.Create(inputAction);
            inputActionTrav.Property("name").SetValue("Sit_Emote");
            inputActionTrav.Property("descriptiveName").SetValue("Sit emote");
            inputActionTrav.Property("userAssignable").SetValue(true);
            inputActionTrav.Property("behaviorId").SetValue(0);

            inputAction     = actions_Copy[actions_Copy.Count - 1];
            inputActionTrav = Traverse.Create(inputAction);
            inputActionTrav.Property("name").SetValue("Alternate_Idle_Emote");
            inputActionTrav.Property("descriptiveName").SetValue("Arms Crossed emote");
            inputActionTrav.Property("userAssignable").SetValue(true);
            inputActionTrav.Property("behaviorId").SetValue(0);

            return(true);
        }
Beispiel #2
0
            public static void InitializePatch(InputManager_Base __instance)
            {
                //s_userData = __instance.userData;

                foreach (var keybindInfo in s_customKeyDict.Values)
                {
                    // This actually creates the new actions:
                    AddRewiredAction(__instance.userData, keybindInfo.name, keybindInfo.category, keybindInfo.type, out int actionID);
                    keybindInfo.actionID = actionID;

                    SL.Log($"Set up custom keybinding '{keybindInfo.name}', actionID: " + keybindInfo.actionID);
                }
            }
Beispiel #3
0
            // The famed Rewired hook
            //private static void InputManager_Base_Initialize(InputManager_Base self)
            public static void Prefix(InputManager_Base __instance)
            {
                // Add our custom actions, which will be exposed in the keybindings menu by tying an action to an "element"--i.e. a keyboard key or joystick input

                // Loop through the infos/descriptions that the user has specified for adding actions
                foreach (InputActionDescription myActionDescription in myActionInfos)
                {
                    // This actually creates the new actions:
                    // The AddRewiredAction method is just a wrapper I made for UserData.AddAction(_categoryId), since it's a little fiddly to configure an InputAction
                    InputAction myNewlyAddedAction = AddRewiredAction(
                        __instance.userData, myActionDescription.name, myActionDescription.type, "No descriptiveName", myActionDescription.categoryId, true); // true for userAssignable

                    // We keep a list of our actions that we've added, so that it's easy to get them later
                    // We also keep the InputActionDescription because we will use it later for sorting & localization
                    myCustomActionIds[myNewlyAddedAction.id] = myActionDescription;
                }
            }
        private void Initialize()
        {
            Deinitialize();
            if (!ReInput.isReady)
            {
                Debug.LogError("You must have an enabled Rewired Input Manager in the scene to use the Cinemachine bridge.");
                return;
            }

            if (_instance != null)
            {
                Debug.LogError("You cannot have multiple Rewired Cinemachine Bridges enabled in the scene.");
                return;
            }
            _instance = this;

            if (_rewiredInputManager == null)
            {
                _rewiredInputManager = GetComponent <InputManager_Base>();
            }

            foreach (var m in _playerMappings)
            {
                if (ReInput.players.GetPlayer(m._playerId) == null)
                {
                    Debug.LogError("No Player exists for id " + m._playerId + ".");
                    continue;
                }
                foreach (var a in m._actionMappings)
                {
                    if (string.IsNullOrEmpty(a._cinemachineAxis))
                    {
                        continue;
                    }

                    InputAction action;
                    if (_rewiredInputManager != null)
                    {
                        if (a._rewiredActionId < 0)
                        {
                            continue;
                        }
                        action = ReInput.mapping.GetAction(a._rewiredActionId);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(a._rewiredActionName))
                        {
                            continue;
                        }
                        action = ReInput.mapping.GetAction(a._rewiredActionName);
                    }
                    if (action == null)
                    {
                        Debug.LogWarning("The Action " + (_rewiredInputManager != null ? "Id " + a._rewiredActionId : "\"" + a._rewiredActionName + "\"") + " does not exist in the Rewired Input Manager.");
                        continue;
                    }
                    if (_mappings.ContainsKey(a._cinemachineAxis))
                    {
                        Debug.LogError("Duplicate Unity Axis found \"" + a._cinemachineAxis + "\". This is not allowed. All Unity Axes must be unique.");
                        continue;
                    }
                    _mappings.Add(a._cinemachineAxis, new PlayerActionMapping()
                    {
                        playerId = m._playerId, actionId = action.id
                    });
                }
            }

            global::Cinemachine.CinemachineCore.GetInputAxis = GetAxis;

            _initialized = true;
        }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            if (_boxStyle == null)
            {
                _boxStyle                    = new GUIStyle(GUI.skin.box);
                _boxStyle.padding            = new RectOffset(5, 5, 5, 5);
                _errorLabel                  = new GUIStyle(GUI.skin.label);
                _errorLabel.fontStyle        = FontStyle.Bold;
                _errorLabel.normal.textColor = Color.red;
            }
            serializedObject.Update();

            EditorGUILayout.Space();

            // Rewired Input Manager link
            SerializedProperty rewiredInputManagerSP = properties[c_rewiredInputManager];
            InputManager_Base  inputManager          = rewiredInputManagerSP.objectReferenceValue as InputManager_Base;
            bool rimIsOnSameGameObject = false;

            if (inputManager == null)
            {
                inputManager = (target as Behaviour).GetComponent <InputManager_Base>();
                if (inputManager != null)
                {
                    rimIsOnSameGameObject = true;
                    if (rewiredInputManagerSP.objectReferenceValue != null)
                    {
                        rewiredInputManagerSP.objectReferenceValue = null;
                    }
                }
            }
            if (!rimIsOnSameGameObject)
            {
                EditorGUILayout.PropertyField(rewiredInputManagerSP);
                if (rewiredInputManagerSP.objectReferenceValue == null)
                {
                    EditorGUILayout.Space();
                    if (GUILayout.Button("Find Rewired Input Manager"))
                    {
                        inputManager = UnityEngine.Object.FindObjectOfType <InputManager_Base>();
                        if (inputManager == null)
                        {
                            Debug.LogWarning("Rewired: No Rewired Input Manager found in the scene.");
                        }
                        else
                        {
                            rewiredInputManagerSP.objectReferenceValue = inputManager;
                        }
                    }
                    EditorGUILayout.Space();
                    EditorGUILayout.HelpBox("Link the Rewired Input Manager you are using here for easier access to Actions, Players, etc. " +
                                            "This will allow you to select Actions from drop downs instead of having to use ids to select items.\n\n" +
                                            "If you are using a Prefab, it is recommended that you link the on-disk Prefab parent here instead of the scene instance.",
                                            MessageType.Info
                                            );
                    EditorGUILayout.Space();
                }

                EditorGUILayout.Separator();
            }

            EditorGUILayout.PropertyField(properties[c_absoluteAxisSensitivity]);
            EditorGUILayout.PropertyField(properties[c_scaleAbsoluteAxesToScreen]);
            EditorGUILayout.PropertyField(properties[c_runInEditMode]);

            EditorGUILayout.Separator();

            // Mappings
            EditorGUILayout.LabelField("Action Mappings", EditorStyles.boldLabel);

            if (Application.isPlaying || properties[c_runInEditMode].boolValue)
            {
                EditorGUILayout.HelpBox("Action mappings can not be edited while the Rewired Cinemachine Bridge is running.", MessageType.Warning);
            }
            else
            {
                if (inputManager != null)
                {
                    UserData userData = inputManager.userData;
                    userData.GetActionIds(_actionIds);
                    userData.GetActionNames(_actionNames);
                    _actionIds.Insert(0, -1);
                    _actionNames.Insert(0, "None");
                    userData.GetPlayerRuntimeIds(_playerIds);
                    userData.GetPlayerNames(_playerNames);
                }

                SerializedProperty mappingsSP = properties[c_playerMappings];
                EditorGUI.indentLevel++;

                float width = EditorGUIUtility.currentViewWidth;

                for (int i = 0; i < mappingsSP.arraySize; i++)
                {
                    SerializedProperty mappingSP        = mappingsSP.GetArrayElementAtIndex(i);
                    SerializedProperty playerIdSP       = mappingSP.FindPropertyRelative(c_playerMapping_playerId);
                    SerializedProperty actionMappingsSP = mappingSP.FindPropertyRelative(c_playerMapping_actionMappings);

                    GUILayout.BeginVertical(_boxStyle, GUILayout.ExpandWidth(false));
                    {
                        bool open;
                        EditorGUILayout.BeginHorizontal();
                        {
                            string key = editorPrefsKeyBase + "_playerMapping_" + i;
                            EditorGUI.BeginChangeCheck();
                            open = EditorGUILayout.Foldout(EditorPrefs.GetBool(key, true), "Entry " + i.ToString());
                            if (EditorGUI.EndChangeCheck())
                            {
                                EditorPrefs.SetBool(key, open);
                            }
                            GUILayout.FlexibleSpace();
                            if (GUILayout.Button("▲", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
                            {
                                _modifyPlayerArrayEvents.Add(new ModifyArrayEvent()
                                {
                                    command = ModifyArrayEvent.Cmd.MoveUp, index = i
                                });
                            }
                            if (GUILayout.Button("▼", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
                            {
                                _modifyPlayerArrayEvents.Add(new ModifyArrayEvent()
                                {
                                    command = ModifyArrayEvent.Cmd.MoveDown, index = i
                                });
                            }
                            if (GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false), GUILayout.Width(miniButtonWidth)))
                            {
                                _modifyPlayerArrayEvents.Add(new ModifyArrayEvent()
                                {
                                    command = ModifyArrayEvent.Cmd.Insert, index = i
                                });
                            }
                            if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false), GUILayout.Width(miniButtonWidth)))
                            {
                                _modifyPlayerArrayEvents.Add(new ModifyArrayEvent()
                                {
                                    command = ModifyArrayEvent.Cmd.Remove, index = i
                                });
                            }
                        }
                        EditorGUILayout.EndVertical();

                        if (open)
                        {
                            EditorGUI.indentLevel++;

                            EditorGUIUtility.labelWidth = 95f;
                            EditorGUIUtility.fieldWidth = Mathf.Max(width * 0.2f, 100f);

                            if (inputManager != null)
                            {
                                int result = EditorGUILayout.IntPopup("Player", playerIdSP.intValue, _playerNames.ToArray(), _playerIds.ToArray(), GUILayout.ExpandWidth(false));
                                if (result != playerIdSP.intValue)
                                {
                                    playerIdSP.intValue = result;
                                }
                            }
                            else
                            {
                                EditorGUILayout.PropertyField(playerIdSP, GUILayout.ExpandWidth(false));
                            }

                            if (IsPlayerIdConflict(mappingsSP, playerIdSP.intValue, i))
                            {
                                EditorGUILayout.LabelField("Duplicate Player Id.", _errorLabel);
                            }

                            GUILayout.Space(5f);
                            EditorGUILayout.LabelField(new GUIContent("Actions"));

                            if (actionMappingsSP.arraySize == 0)
                            {
                                EditorGUILayout.LabelField("Press \"Add Action\" to add an Action.");
                                if (GUILayout.Button("Add Action"))
                                {
                                    actionMappingsSP.InsertArrayElementAtIndex(actionMappingsSP.arraySize);
                                }
                            }
                            for (int j = 0; j < actionMappingsSP.arraySize; j++)
                            {
                                EditorGUIUtility.labelWidth = 140f;
                                EditorGUIUtility.fieldWidth = Mathf.Max(width * 0.2f, 100f);

                                SerializedProperty actionMappingSP = actionMappingsSP.GetArrayElementAtIndex(j);
                                SerializedProperty unityAxisSP     = actionMappingSP.FindPropertyRelative(c_actionMapping_cinemachineAxis);

                                EditorGUILayout.BeginHorizontal();
                                {
                                    EditorGUILayout.PropertyField(unityAxisSP);
                                    GUILayout.Space(-25f);

                                    SerializedProperty rewiredActionNameSP = actionMappingSP.FindPropertyRelative(c_actionMapping_rewiredActionName);
                                    SerializedProperty rewiredActionIdSP   = actionMappingSP.FindPropertyRelative(c_actionMapping_rewiredActionId);

                                    EditorGUIUtility.labelWidth = 125f;

                                    if (inputManager != null)
                                    {
                                        int result = EditorGUILayout.IntPopup("Rewired Action", rewiredActionIdSP.intValue, _actionNames.ToArray(), _actionIds.ToArray(), GUILayout.ExpandWidth(false));
                                        if (result != rewiredActionIdSP.intValue)
                                        {
                                            rewiredActionIdSP.intValue = result;
                                        }
                                    }
                                    else
                                    {
                                        EditorGUILayout.PropertyField(rewiredActionNameSP, new GUIContent("Rewired Action"), GUILayout.ExpandWidth(false));
                                    }

                                    GUILayout.Space(-10f);
                                    GUILayout.FlexibleSpace();
                                    GUILayout.BeginVertical();
                                    {
                                        if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false), GUILayout.Width(miniButtonWidth)))
                                        {
                                            _modifyActionArrayEvents.Add(new ModifyArrayEvent()
                                            {
                                                command = ModifyArrayEvent.Cmd.Remove, index = j
                                            });
                                        }
                                    }
                                    GUILayout.EndVertical();
                                }
                                EditorGUILayout.EndHorizontal();

                                if (IsUnityAxisConflict(mappingsSP, actionMappingsSP, unityAxisSP.stringValue, i, j))
                                {
                                    EditorGUILayout.LabelField("Duplicate Cinemachine Axis name.", _errorLabel);
                                }
                            }

                            if (actionMappingsSP.arraySize > 0)
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false), GUILayout.Width(miniButtonWidth)))
                                    {
                                        _modifyActionArrayEvents.Add(new ModifyArrayEvent()
                                        {
                                            command = ModifyArrayEvent.Cmd.Insert, index = actionMappingsSP.arraySize
                                        });
                                    }
                                }
                                GUILayout.EndHorizontal();
                            }

                            ModifyArray(actionMappingsSP, _modifyActionArrayEvents);

                            EditorGUI.indentLevel--;
                        }
                        else
                        {
                            bool error = false;
                            if (IsPlayerIdConflict(mappingsSP, playerIdSP.intValue, i))
                            {
                                error = true;
                            }
                            for (int j = 0; j < actionMappingsSP.arraySize; j++)
                            {
                                if (IsUnityAxisConflict(mappingsSP, actionMappingsSP, actionMappingsSP.GetArrayElementAtIndex(j).FindPropertyRelative(c_actionMapping_cinemachineAxis).stringValue, i, j))
                                {
                                    error = true;
                                }
                            }
                            if (error)
                            {
                                EditorGUILayout.HelpBox("This entry contains errors which must be fixed.", MessageType.Error);
                            }
                        }
                    }
                    GUILayout.EndVertical();
                }
                EditorGUI.indentLevel--;

                ModifyArray(mappingsSP, _modifyPlayerArrayEvents);

                if (mappingsSP.arraySize == 0)
                {
                    EditorGUILayout.LabelField("Press \"Add Entry\" to add an entry.");
                    if (GUILayout.Button("Add Entry"))
                    {
                        mappingsSP.InsertArrayElementAtIndex(mappingsSP.arraySize);
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();

            EditorGUILayout.Space();

            //base.DrawDefaultInspector();
        }