Exemplo n.º 1
0
        protected virtual void HandleSelectButtonReleased(XboxControllerEventData eventData)
        {
            InputManager.Instance.RaiseSourceUp(eventData.InputSource, eventData.SourceId, InteractionSourcePressInfo.Select);

            if (HoldStartedRoutine != null)
            {
                StopCoroutine(HoldStartedRoutine);
            }

            switch (CurrentGestureState)
            {
            case GestureState.NavigationStarted:
                InputManager.Instance.RaiseNavigationCompleted(eventData.InputSource, eventData.SourceId, Vector3.zero);
                break;

            case GestureState.HoldStarted:
                InputManager.Instance.RaiseHoldCompleted(eventData.InputSource, eventData.SourceId);
                break;

            default:
                InputManager.Instance.RaiseInputClicked(eventData.InputSource, eventData.SourceId, InteractionSourcePressInfo.Select, 1);
                break;
            }

            CurrentGestureState = GestureState.SelectButtonUnpressed;
        }
        public static float GetAxis(XboxControllerMappingTypes axisType, XboxControllerEventData eventData)
        {
            switch (axisType)
            {
            case XboxControllerMappingTypes.XboxLeftStickHorizontal:
                return(eventData.XboxLeftStickHorizontalAxis);

            case XboxControllerMappingTypes.XboxLeftStickVertical:
                return(eventData.XboxLeftStickVerticalAxis);

            case XboxControllerMappingTypes.XboxRightStickHorizontal:
                return(eventData.XboxRightStickHorizontalAxis);

            case XboxControllerMappingTypes.XboxRightStickVertical:
                return(eventData.XboxRightStickVerticalAxis);

            case XboxControllerMappingTypes.XboxDpadHorizontal:
                return(eventData.XboxDpadHorizontalAxis);

            case XboxControllerMappingTypes.XboxDpadVertical:
                return(eventData.XboxDpadVerticalAxis);

            case XboxControllerMappingTypes.XboxLeftTrigger:
                return(eventData.XboxLeftTriggerAxis);

            case XboxControllerMappingTypes.XboxRightTrigger:
                return(eventData.XboxRightTriggerAxis);

            case XboxControllerMappingTypes.XboxSharedTrigger:
                return(eventData.XboxSharedTriggerAxis);

            default:
                throw new ArgumentOutOfRangeException("axisType", axisType, null);
            }
        }
Exemplo n.º 3
0
        public virtual void OnXboxInputUpdate(XboxControllerEventData eventData)
        {
            if (string.IsNullOrEmpty(GamePadName))
            {
                GamePadName = eventData.GamePadName;
            }

            if (XboxControllerMapping.GetButton_Down(SelectButton, eventData))
            {
                CurrentGestureState = GestureState.SelectButtonPressed;

                InputManager.Instance.RaiseSourceDown(eventData.InputSource, eventData.SourceId, InteractionSourcePressInfo.Select);

                HoldStartedRoutine = StartCoroutine(HandleHoldStarted(eventData));
            }

            if (XboxControllerMapping.GetButton_Pressed(SelectButton, eventData))
            {
                HandleNavigation(eventData);
            }

            if (XboxControllerMapping.GetButton_Up(SelectButton, eventData))
            {
                HandleSelectButtonReleased(eventData);
            }

            // Consume this event
            eventData.Use();
        }
Exemplo n.º 4
0
        protected virtual void HandleNavigation(XboxControllerEventData eventData)
        {
            float displacementAlongX = XboxControllerMapping.GetAxis(HorizontalNavigationAxis, eventData);
            float displacementAlongY = XboxControllerMapping.GetAxis(VerticalNavigationAxis, eventData);

            if (displacementAlongX == 0.0f && displacementAlongY == 0.0f && CurrentGestureState != GestureState.NavigationStarted)
            {
                return;
            }

            NormalizedOffset.x = displacementAlongX;
            NormalizedOffset.y = displacementAlongY;
            NormalizedOffset.z = 0f;

            if (CurrentGestureState != GestureState.NavigationStarted)
            {
                if (CurrentGestureState == GestureState.HoldStarted)
                {
                    InputManager.Instance.RaiseHoldCanceled(eventData.InputSource, eventData.SourceId);
                }

                CurrentGestureState = GestureState.NavigationStarted;

                // Raise navigation started event.
                InputManager.Instance.RaiseNavigationStarted(eventData.InputSource, eventData.SourceId);
            }
            else
            {
                // Raise navigation updated event.
                InputManager.Instance.RaiseNavigationUpdated(eventData.InputSource, eventData.SourceId, NormalizedOffset);
            }
        }
Exemplo n.º 5
0
        protected virtual IEnumerator HandleHoldStarted(XboxControllerEventData eventData)
        {
            yield return(new WaitForSeconds(HoldStartedInterval));

            if (CurrentGestureState == GestureState.HoldStarted || CurrentGestureState == GestureState.NavigationStarted)
            {
                yield break;
            }

            CurrentGestureState = GestureState.HoldStarted;

            InputManager.Instance.RaiseHoldStarted(eventData.InputSource, eventData.SourceId);
        }
        private void InitializeEventDatas()
        {
            inputEventData           = new InputEventData(EventSystem.current);
            sourceClickedEventData   = new InputClickedEventData(EventSystem.current);
            sourceStateEventData     = new SourceStateEventData(EventSystem.current);
            manipulationEventData    = new ManipulationEventData(EventSystem.current);
            navigationEventData      = new NavigationEventData(EventSystem.current);
            holdEventData            = new HoldEventData(EventSystem.current);
            pointerSpecificEventData = new PointerSpecificEventData(EventSystem.current);
            inputPositionEventData   = new InputPositionEventData(EventSystem.current);
            selectPressedEventData   = new SelectPressedEventData(EventSystem.current);
            sourceRotationEventData  = new SourceRotationEventData(EventSystem.current);
            sourcePositionEventData  = new SourcePositionEventData(EventSystem.current);
            xboxControllerEventData  = new XboxControllerEventData(EventSystem.current);
#if UNITY_WSA || UNITY_STANDALONE_WIN
            speechEventData    = new SpeechEventData(EventSystem.current);
            dictationEventData = new DictationEventData(EventSystem.current);
#endif
        }
        public static bool GetButton_Up(XboxControllerMappingTypes buttonType, XboxControllerEventData eventData)
        {
            switch (buttonType)
            {
            case XboxControllerMappingTypes.None:
                return(false);

            case XboxControllerMappingTypes.XboxA:
                return(eventData.XboxA_Up);

            case XboxControllerMappingTypes.XboxB:
                return(eventData.XboxB_Up);

            case XboxControllerMappingTypes.XboxX:
                return(eventData.XboxX_Up);

            case XboxControllerMappingTypes.XboxY:
                return(eventData.XboxY_Up);

            case XboxControllerMappingTypes.XboxView:
                return(eventData.XboxView_Up);

            case XboxControllerMappingTypes.XboxMenu:
                return(eventData.XboxMenu_Up);

            case XboxControllerMappingTypes.XboxLeftBumper:
                return(eventData.XboxLeftBumper_Up);

            case XboxControllerMappingTypes.XboxRightBumper:
                return(eventData.XboxRightBumper_Up);

            case XboxControllerMappingTypes.XboxLeftStickClick:
                return(eventData.XboxLeftStick_Up);

            case XboxControllerMappingTypes.XboxRightStickClick:
                return(eventData.XboxRightStick_Up);

            default:
                throw new ArgumentOutOfRangeException("buttonType", buttonType, null);
            }
        }
Exemplo n.º 8
0
 protected static bool OnButton_Down(XboxControllerMappingTypes buttonType, XboxControllerEventData eventData)
 {
     return(XboxControllerMapping.GetButton_Down(buttonType, eventData));
 }