Beispiel #1
0
        // update the cursor location and whether it is enabled
        // this code is based on Unity's DragMe.cs code provided in the UI drag and drop example
        private void UpdateCursor(ArbitraryInput pointer, PointerEventData pointData)
        {
            if (pointer.PointEvent.pointerCurrentRaycast.gameObject != null)
            {
                pointer.isHittingUI = true;

                if (pointData.pointerEnter != null)
                {
                    RectTransform draggingPlane = pointData.pointerEnter.GetComponent <RectTransform>();
                    Vector3       globalLookPos;
                    if (RectTransformUtility.ScreenPointToWorldPointInRectangle(draggingPlane, pointData.position, pointData.enterEventCamera, out globalLookPos))
                    {
                        pointer.CursorPosition = globalLookPos;
                        pointer.CursorRotation = draggingPlane.rotation;

                        float lookPointDistance = (pointer.CursorPosition - Camera.main.transform.position).magnitude;
                        float cursorScale       = lookPointDistance * NormalCursorScale;
                        if (cursorScale < NormalCursorScale)
                        {
                            cursorScale = NormalCursorScale;
                        }

                        pointer.CursorScale = Vector3.one * cursorScale;
                    }
                }
            }
            else
            {
                pointer.isHittingUI = false;
            }
        }
Beispiel #2
0
        // use screen midpoint as locked pointer location, enabling look location to be the "mouse"
        private bool GetLookPointerEventData(ArbitraryInput pointer)
        {
            if (pointer.PointEvent == null)
            {
                pointer.PointEvent = new PointerEventData(base.eventSystem);
            }
            else
            {
                pointer.PointEvent.Reset();
            }

            pointer.PointEvent.delta       = Vector2.zero;
            pointer.PointEvent.position    = new Vector2(Screen.width / 2, Screen.height / 2);
            pointer.PointEvent.scrollDelta = Vector2.zero;

            base.eventSystem.RaycastAll(pointer.PointEvent, m_RaycastResultCache);
            pointer.PointEvent.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache);
            if (pointer.PointEvent.pointerCurrentRaycast.gameObject != null)
            {
                GuiHit = true; //gets set to false at the beginning of the process event
            }

            m_RaycastResultCache.Clear();

            return(true);
        }
Beispiel #3
0
 private void UpdateCameraPosition(ArbitraryInput pointer)
 {
     ControllerCamera.transform.position = pointer.transform.position;
     ControllerCamera.transform.forward  = pointer.transform.forward;
 }