/// <summary>
        /// Navigation Updated event fires an message event upwards on the focus object for "NavigationUpdated"
        /// and calls OnNavigationUpdated for InteractibleObjects
        /// </summary>
        /// <param name="focuser"></param>
        /// <param name="relativePosition"></param>
        /// <param name="ray"></param>
        private void NavigationUpdatedEvent(AFocuser focuser, Vector3 relativePosition, Ray ray)
        {
            IsNavigating = true;

            if (focuser != null)
            {
                GameObject           focusObject = focuser.PrimeFocus;
                InteractionEventArgs eventArgs   = new InteractionEventArgs(focuser, relativePosition, true, ray);

                if (focusObject != null)
                {
                    focusObject.SendMessage("NavigationUpdated", eventArgs, SendMessageOptions.DontRequireReceiver);
                    SendEvent(OnNavigationUpdated, focusObject, eventArgs);
                }

                WorldGraphicsRaycaster.RayEventData pointerEventData = focuser.GetPointerData() as WorldGraphicsRaycaster.RayEventData;
                if (pointerEventData.pointerDrag != null)
                {
                    pointerEventData.delta = relativePosition;
                    Vector2 curPos = pointerEventData.position;

                    pointerEventData.CurrentAddition += relativePosition * pointerEventData.ScaleMultiplier;
                    Vector3 offsetpos = pointerEventData.InitialDragHandPos + pointerEventData.CurrentAddition;

                    pointerEventData.position = Camera.main.WorldToScreenPoint(offsetpos);
                    FocusManager.Instance.ExecuteUIFocusEvent(pointerEventData.pointerDrag, pointerEventData, ExecuteEvents.dragHandler);

                    pointerEventData.position = curPos;
                }
            }
        }
Пример #2
0
        public PointerEventData GetPointerData()
        {
            if (m_PointerData == null)
            {
                m_PointerData = new WorldGraphicsRaycaster.RayEventData(EventSystem.current, this);
            }

            m_PointerData.EventRay = new Ray(TargetOrigin, TargetDirection);
            m_PointerData.position = new Vector2(Camera.main.pixelWidth * 0.5f, Camera.main.pixelHeight * 0.5f);
            if (FocusHitInfo != null)
            {
                m_PointerData.pointerCurrentRaycast = FocusHitInfo.raycastResult;
                m_PointerData.pointerPressRaycast   = FocusHitInfo.raycastResult;
                m_PointerData.position = Camera.main.WorldToScreenPoint(FocusHitInfo.raycastResult.worldPosition);
            }

            m_PointerData.pressPosition = m_PointerData.position;

            return(m_PointerData);
        }
        /// <summary>
        /// Navigation Started event fires an message event upwards on the focus object for "NavigationStarted"
        /// and calls OnNavigationStarted for InteractibleObjects
        /// </summary>
        /// <param name="focuser"></param>
        /// <param name="relativePosition"></param>
        /// <param name="ray"></param>
        private void NavigationStartedEvent(AFocuser focuser, Vector3 relativePosition, Ray ray)
        {
            IsNavigating = true;

            if (focuser != null)
            {
                GameObject           focusObject = focuser.PrimeFocus;
                InteractionEventArgs eventArgs   = new InteractionEventArgs(focuser, relativePosition, true, ray);

                if (focusObject != null)
                {
                    focusObject.SendMessage("NavigationStarted", eventArgs, SendMessageOptions.DontRequireReceiver);
                    SendEvent(OnNavigationStarted, focusObject, eventArgs);
                    CheckLockFocus(focuser);
                }

                if (focuser.UIInteractibleFocus != null)
                {
                    WorldGraphicsRaycaster.RayEventData eventData = focuser.GetPointerData() as WorldGraphicsRaycaster.RayEventData;

                    FocusManager.Instance.ExecuteUIFocusEvent(focuser.UIInteractibleFocus, eventData, ExecuteEvents.pointerDownHandler);
                    eventData.pointerPress   = focuser.UIInteractibleFocus;
                    eventData.selectedObject = focuser.UIInteractibleFocus;

                    eventData.dragging         = true;
                    eventData.eligibleForClick = false;
                    eventData.pointerDrag      = focuser.UIInteractibleFocus;

                    Vector2 curPos = eventData.position;
                    eventData.InitialDragHandPos = eventData.pointerPressRaycast.worldPosition + (Camera.main.transform.forward * eventData.pointerPressRaycast.distance);
                    eventData.position           = Camera.main.WorldToScreenPoint(eventData.InitialDragHandPos);

                    FocusManager.Instance.ExecuteUIFocusEvent(focuser.UIInteractibleFocus, eventData, ExecuteEvents.beginDragHandler);

                    eventData.position        = curPos;
                    eventData.CurrentAddition = Vector2.zero;
                }
            }
        }