Esempio n. 1
0
        protected virtual void Awake()
        {
            input    = FindObjectOfType <InputBehavior>();
            assigner = FindObjectOfType <JoystickAssigner>();

            if (AutomaticallyRequestJoystick)
            {
                // TODO: Push this to a function
                FocusedJoystick = assigner.RequestOpenJoystick();
                if (FocusedJoystick != null)
                {
                    JoystickID = JoystickAssigner.GetJoyID(FocusedJoystick);
                }
                else
                {
                    Debug.LogError("Error: No Joysticks available!");
                }
            }
        }
Esempio n. 2
0
        public virtual void UnregisterInput()
        {
            if (FocusedJoystick == null || _bRegistered == false)
            {
                return;
            }

            input.UnregisterKey(JoystickID + "TopFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.TopFaceButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "LeftFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.LeftFaceButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "RightFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.RightFaceButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "BottomFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.BottomFaceButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "LeftBump", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.LeftShoulderButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "RightBump", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.RightShoulderButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "Start", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.StartButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "Select", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.SelectButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "Home", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.HomeButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "LeftAnalogClick", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.LeftAnalogButton), BroadcastKeyState.PRESSED);
            input.UnregisterKey(JoystickID + "RightAnalogClick", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.RightAnalogButton), BroadcastKeyState.PRESSED);

            input.UnregisterKey(JoystickID + "TopFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.TopFaceButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "LeftFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.LeftFaceButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "RightFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.RightFaceButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "BottomFace", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.BottomFaceButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "LeftBump", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.LeftShoulderButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "RightBump", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.RightShoulderButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "Start", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.StartButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "Select", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.SelectButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "Home", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.HomeButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "LeftAnalogClick", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.LeftAnalogButton), BroadcastKeyState.RELEASED);
            input.UnregisterKey(JoystickID + "RightAnalogClick", JoystickAssigner.JoystickKeycode(JoystickID, LayoutMap.RightAnalogButton), BroadcastKeyState.RELEASED);

            input.UnregisterAxis(JoystickID + "LeftAnalog", false, JoystickID + LayoutMap.LeftAnalogAxisX, JoystickID + LayoutMap.LeftAnalogAxisY);
            input.UnregisterAxis(JoystickID + "RightAnalog", false, JoystickID + LayoutMap.RightAnalogAxisX, JoystickID + LayoutMap.RightAnalogAxisY);
            input.UnregisterAxis(JoystickID + "DPad", false, JoystickID + LayoutMap.DirectionAxisX, JoystickID + LayoutMap.DirectionAxisY);
            input.UnregisterAxis(JoystickID + "LeftTrigger", false, JoystickID + LayoutMap.LeftTriggerAxis);
            input.UnregisterAxis(JoystickID + "RightTrigger", false, JoystickID + LayoutMap.RightTriggerAxis);

            // listen for the input events
            RetroEvents.Chapter("Input_" + JoystickID + "TopFace").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "LeftFace").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "RightFace").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "BottomFace").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "LeftBump").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "RightBump").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "Start").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "Select").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "Home").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "LeftAnalogClick").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "RightAnalogClick").Unsubscribe <KeyInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "LeftAnalog").Unsubscribe <AxisInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "RightAnalog").Unsubscribe <AxisInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "DPad").Unsubscribe <AxisInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "LeftTrigger").Unsubscribe <AxisInputEvent>(this);
            RetroEvents.Chapter("Input_" + JoystickID + "RightTrigger").Unsubscribe <AxisInputEvent>(this);

            // handle custom keys
            foreach (KeyValuePair <string, KeyBind> pair in LayoutMap.CustomKeyBind.D)
            {
                input.UnregisterKey(JoystickID + pair.Key, JoystickAssigner.JoystickKeycode(JoystickID, pair.Value.PlatformKeyID), BroadcastKeyState.HELD);
                RetroEvents.Chapter("Input_" + JoystickID + pair.Key).Unsubscribe <KeyInputEvent>(this);
            }


            // handle custom axis
            foreach (KeyValuePair <string, AxisBind> pair in LayoutMap.CustomAxisBind.D)
            {
                input.UnregisterAxis(JoystickID + pair.Key, false, JoystickID + pair.Value.PlatformAxisID);
                RetroEvents.Chapter("Input_" + JoystickID + pair.Key).Unsubscribe <AxisInputEvent>(this);
            }

            _bRegistered = false;
        }