public static Dictionary <int, RewiredInputs> m_playerInputManager = (Dictionary <int, RewiredInputs>) typeof(ControlsInput).GetField("m_playerInputManager", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); // null for static field

        //
        // USE THIS METHOD TO EASILY ADD ACTIONS AND KEYBINDINGS FOR YOUR MOD
        //
        // The name arg is displayed in the keybindings menu
        //
        // The categoryId arg determines where in the keybindings list this action will appear
        //
        // The showForController arg determines if this action can also be bound to a controller
        //
        // The sectionId arg is a weird number. It somehow affects where in the list of keybindings
        // the action appears but I haven't figured out yet what it means. I just try different numbers
        // from 0-5 until I'm happy with where in the list the keybind ends up
        //
        public static void AddAction(string name, KeybindingsCategory categoryId, ControlType controlType, int sectionId = 0, InputActionType type = InputActionType.Button)
        {
            // The user does not have to initialize or instantiate anything themselves to use custom keybinds
            // Just call AddAction() and we'll make sure the plumbing is there
            if (orig_Initialize == null)
            {
                InitHooks();
            }

            // Capture the info the user has specified for the action they would like to create
            InputActionDescription protoAction = new InputActionDescription(name, (int)categoryId, controlType, sectionId, type);

            myActionInfos.Add(protoAction);

            // If this method is called after InputManager_Base.Initialize() has been called, then these actions won't be added
            // So let's report that back to the mod maker to avoid headaches
            bool shouldReportTooLateAdd = false;

            if (shouldReportTooLateAdd)
            {
                bool alreadyInitialized = (bool)typeof(ReInput).GetProperty("initialized", BindingFlags.NonPublic | BindingFlags.Static).GetGetMethod(true).Invoke(null, null);
                if (alreadyInitialized)
                {
                    MyLogger.LogDebug("Tried to add action too late. Add your action earlier in the life cycle.");
                }
            }
        }
예제 #2
0
        public KeybindInfo(string name, KeybindingsCategory category, ControlType controllerType, InputType type)
        {
            this.name           = name;
            this.category       = category;
            this.controllerType = controllerType;
            this.type           = type;

            this.keyIDs   = new int[2];
            this.actionID = -1;
        }
예제 #3
0
        /// <summary>Use this to add a new Keybinding to the game.</summary>
        /// <param name="name">The name for the keybinding displayed in the menu.</param>
        /// <param name="category">The category to add to</param>
        /// <param name="controlType">What type of control this is</param>
        /// <param name="type">What type(s) of input it will accept</param>
        public static void AddAction(string name, KeybindingsCategory category, ControlType controlType = ControlType.Keyboard, InputType type = InputType.Button)
        {
            bool initialized = (bool)At.GetPropertyStatic(typeof(ReInput), "initialized");

            if (initialized)
            {
                SL.LogWarning("Tried to add Custom Keybinding too late. Add your keybinding earlier, such as in your BaseUnityPlugin.Awake() method.");
                return;
            }

            if (s_customKeyDict.ContainsKey(name))
            {
                SL.LogWarning($"Attempting to add a keybind '{name}', but one with this name has already been registered.");
                return;
            }

            var customKey = new KeybindInfo(name, category, controlType, type);

            s_customKeyDict.Add(name, customKey);
        }
예제 #4
0
        // Actually add the Rewired control map

        internal static InputAction AddRewiredAction(UserData userData, string name, KeybindingsCategory category, InputType type, out int actionID)
        {
            int[] preAddIDs = userData.GetActionIds();

            // Add an action to the data store
            userData.AddAction((int)category);

            actionID = userData.GetActionIds().Where(it => !preAddIDs.Contains(it)).FirstOrDefault();

            // Get a reference to the added action
            var inputAction = userData.GetActionById(actionID);

            // Configure our action according to args
            At.SetField(inputAction, "_name", name);
            At.SetField(inputAction, "_descriptiveName", name);
            At.SetField(inputAction, "_type", (InputActionType)type);
            At.SetField(inputAction, "_userAssignable", true);
            At.SetField(inputAction, "_categoryId", (int)category);

            return(inputAction);
        }