Forum rules - please read before posting.

Rewired Integration - Detect Input change and run actionlist script

edited October 2021 in Extending the editor

Hey folks,

Sharing this in case anyone else finds it useful. I've written a script that uses a Rewired delegate to detect what the last used input device was and trigger an action list depending if it's a joystick, or keyboard & mouse.

You could also then use this to also change AC's input method or do anything else you think is necessary on input change.

An example of it in action:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    using Rewired;

    public class ChangeControllerMap : MonoBehaviour
    {
        private Rewired.Player player;

        public ActionList actionListKeyboardMouse;
        public ActionList actionListJoystick;

        private bool isUsingKeyboardAndMouse = false;

        private void Awake()
        {
            player = ReInput.players.GetPlayer(0);
            player.controllers.AddLastActiveControllerChangedDelegate(OnControllerChange);
        }

        void OnControllerChange(Rewired.Player player, Controller controller)
        {
            switch (controller.type)
            {
                case ControllerType.Joystick:
                    ControlPad();
                    break;

                case ControllerType.Mouse:
                case ControllerType.Keyboard:
                    KeyboardAndMouse();
                    break;
            }
        }

        void ControlPad()
        {
            print("Joystick");
            actionListJoystick.Interact();

            isUsingKeyboardAndMouse = false;
        }

        void KeyboardAndMouse()
        {
            if (!isUsingKeyboardAndMouse)
            {
                print("Keyboard & Mouse");
                actionListKeyboardMouse.Interact();

                isUsingKeyboardAndMouse = true;
            }
        }
    }
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.