Esempio n. 1
0
    private void SetDraggedPosition(PointerEventData eventData)
    {
        if (eventData.pointerEnter != null && eventData.pointerEnter.transform as RectTransform != null)
        {
            plane = eventData.pointerEnter.transform as RectTransform;
        }

        var     rt = newObj.GetComponent <RectTransform>();
        Vector3 globalMousePos;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(plane, eventData.position, eventData.pressEventCamera, out globalMousePos))
        {
            rt.position = globalMousePos;
            rt.rotation = plane.rotation;
        }
    }
Esempio n. 2
0
    private void SetDraggedPosition(PointerEventData data)
    {
        if (data.pointerEnter != null && data.pointerEnter.transform as RectTransform != null)
        {
            draggingPlane = data.pointerEnter.transform as RectTransform;
        }

        var     rt = draggingObject.GetComponent <RectTransform>();
        Vector3 globalMousePos;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(draggingPlane, data.position, data.pressEventCamera, out globalMousePos))
        {
            rt.position = globalMousePos;
            rt.rotation = draggingPlane.rotation;
        }
    }
Esempio n. 3
0
        protected virtual void TranslateUI(Vector2 screenDelta)
        {
            // Screen position of the transform
            var screenPoint = RectTransformUtility.WorldToScreenPoint(Camera, transform.position);

            // Add the deltaPosition
            screenPoint += screenDelta;

            // Convert back to world space
            var worldPoint = default(Vector3);

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(transform.parent as RectTransform, screenPoint, Camera, out worldPoint) == true)
            {
                transform.position = worldPoint;
            }
        }
Esempio n. 4
0
    public bool IsRaycastLocationValid(Vector2 screenPos, Camera eventCamera)
    {
        var worldPoint = Vector3.zero;
        var isInside   = RectTransformUtility.ScreenPointToWorldPointInRectangle(
            rectTransform,
            screenPos,
            eventCamera,
            out worldPoint
            );

        if (isInside)
        {
            isInside = myCollider.OverlapPoint(worldPoint);
        }
        return(isInside);
    }
Esempio n. 5
0
    private void SetDraggedPosition(PointerEventData eventData)
    {
        if (this.dragOnSurfaces && (Object)eventData.pointerEnter != (Object)null && (Object)(eventData.pointerEnter.transform as RectTransform) != (Object)null)
        {
            this.m_DraggingPlanes[eventData.pointerId] = eventData.pointerEnter.transform as RectTransform;
        }
        RectTransform component = this.m_DraggingIcons[eventData.pointerId].GetComponent <RectTransform>();
        Vector3       worldPoint;

        if (!RectTransformUtility.ScreenPointToWorldPointInRectangle(this.m_DraggingPlanes[eventData.pointerId], eventData.position, eventData.pressEventCamera, out worldPoint))
        {
            return;
        }
        component.position = worldPoint;
        component.rotation = this.m_DraggingPlanes[eventData.pointerId].rotation;
    }
Esempio n. 6
0
        protected override void onRefresh()
        {
            Camera menuCamera = PlayerView.Binder.MenuSystem.MenuCamera;

            if (this.m_clickedRectTm != null)
            {
                Vector3 vector2;
                Vector3 screenPoint = menuCamera.WorldToScreenPoint(this.m_clickedRectTm.position);
                RectTransformUtility.ScreenPointToWorldPointInRectangle(base.RectTm, screenPoint, menuCamera, out vector2);
                this.ArrowRectTm.position = new Vector3(vector2.x, this.ArrowRectTm.position.y, this.ArrowRectTm.position.z);
            }
            else
            {
                Debug.LogWarning("Valid RectTransform not found for click handling.");
            }
        }
    public void OnPointerDown(PointerEventData eventData)
    {
        offset = Vector3.zero;

        if (imageContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(imageRect, eventData.position, eventData.enterEventCamera))
        {
            Vector3 mousePos;
            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(imageRect, eventData.position, eventData.enterEventCamera, out mousePos))
                offset = mousePos - imageRect.position;

            LScene.GetInstance().IsSettingParmsUsingIcon = true;
            image.raycastTarget = false;

            SetTipActive(false);
        }
    }
Esempio n. 8
0
 private void UpdateCursor(PointerEventData lookData)
 {
     if (cursor != null)
     {
         if (useCursor)
         {
             if (lookData.pointerEnter != null)
             {
                 RectTransform draggingPlane = lookData.pointerEnter.GetComponent <RectTransform>();
                 Vector3       globalLookPos;
                 if (RectTransformUtility.ScreenPointToWorldPointInRectangle(draggingPlane, lookData.position, lookData.enterEventCamera, out globalLookPos))
                 {
                     cursor.gameObject.SetActive(true);
                     cursor.position = globalLookPos;
                     cursor.rotation = draggingPlane.rotation;
                     if (scaleCursorWithDistance)
                     {
                         // scale cursor with distance
                         float lookPointDistance = (globalLookPos - lookData.enterEventCamera.transform.position).magnitude;
                         float cursorScale       = lookPointDistance * normalCursorScale;
                         if (cursorScale < normalCursorScale)
                         {
                             cursorScale = normalCursorScale;
                         }
                         Vector3 cursorScaleVector;
                         cursorScaleVector.x = cursorScale;
                         cursorScaleVector.y = cursorScale;
                         cursorScaleVector.z = cursorScale;
                         cursor.localScale   = cursorScaleVector;
                     }
                 }
                 else
                 {
                     cursor.gameObject.SetActive(false);
                 }
             }
             else
             {
                 cursor.gameObject.SetActive(false);
             }
         }
         else
         {
             cursor.gameObject.SetActive(false);
         }
     }
 }
Esempio n. 9
0
        protected virtual void TranslateUI(float pinchScale, Vector2 pinchScreenCenter)
        {
            // Screen position of the transform
            var screenPoint = RectTransformUtility.WorldToScreenPoint(Camera, transform.position);

            // Push the screen position away from the reference point based on the scale
            screenPoint.x = pinchScreenCenter.x + (screenPoint.x - pinchScreenCenter.x) * pinchScale;
            screenPoint.y = pinchScreenCenter.y + (screenPoint.y - pinchScreenCenter.y) * pinchScale;

            // Convert back to world space
            var worldPoint = default(Vector3);

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(transform.parent as RectTransform, screenPoint, Camera, out worldPoint) == true)
            {
                transform.position = worldPoint;
            }
        }
Esempio n. 10
0
    private Vector2 GetJoystickOffset(Vector2 inPos)
    {
        Vector3 globalHandle;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(canvas, inPos, UICamera, out globalHandle))
        {
            handler.position = globalHandle;
        }
        var handleOffset = handler.anchoredPosition;

        if (handleOffset.magnitude > radius)
        {
            handleOffset             = handleOffset.normalized * radius;
            handler.anchoredPosition = handleOffset;
        }
        return(handleOffset);
    }
Esempio n. 11
0
    void Start()
    {
        instance = this;

        LineDrawer            = GetComponent <LineRenderer>();
        LineDrawer.startColor = Color.grey;
        LineDrawer.endColor   = Color.grey;

        Vector3 worldPoint;

        RectTransformUtility.ScreenPointToWorldPointInRectangle(
            GetComponent <RectTransform>(),
            gameObject.transform.position, Camera.main, out worldPoint);

        basex = worldPoint.x;
        basey = worldPoint.y;
    }
Esempio n. 12
0
    // Вызывается в ходе перемещения
    public void OnDrag(PointerEventData eventData)
    {
        // Определить текущие мировые координаты точки контакта пальца с экраном
        Vector3 worldPoint = new Vector3();

        RectTransformUtility.ScreenPointToWorldPointInRectangle(this.transform as RectTransform, eventData.position, eventData.enterEventCamera, out worldPoint);
        // Поместить площадку в эту точку
        thumb.position = worldPoint;
        // Вычислить смещение от исходной позиции
        var size = _rectTransform.rect.size;

        delta    = thumb.localPosition;
        delta.x /= size.x / 2.0f;
        delta.y /= size.y / 2.0f;
        delta.x  = Mathf.Clamp(delta.x, -1.0f, 1.0f);
        delta.y  = Mathf.Clamp(delta.y, -1.0f, 1.0f);
    }
Esempio n. 13
0
 // Update is called once per frame
 void Update()
 {
     if (Traget != null)
     {
         Vector2 screenPos = Camera.main.WorldToScreenPoint(Traget.position);
         Vector3 globalMousePos;
         if (RectTransformUtility.ScreenPointToWorldPointInRectangle(Self, screenPos, /*null*/ cav.worldCamera, out globalMousePos))
         {
             //Debug.LogError ("hit");
             Self.position = globalMousePos;
         }
         else
         {
             //Debug.LogError ("not hit");
         }
     }
 }
Esempio n. 14
0
    private void SetDraggedPosition(PointerEventData eventData, bool flag = false)
    {
        var     rt = transform.GetChild(0).GetComponent <RectTransform>();
        Vector3 globalMousePos;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(rt, eventData.position, eventData.pressEventCamera, out globalMousePos))
        {
            if (flag)
            {
                interval = globalMousePos - rt.position;
            }
            else
            {
                rt.position = globalMousePos - interval;
            }
        }
    }
Esempio n. 15
0
    private void SetDraggedPosition(PointerEventData eventData)
    {
        if (dragOnSurfaces && eventData.pointerEnter != null && eventData.pointerEnter.transform as RectTransform != null)
        {
            m_DraggingPlanes[eventData.pointerId] = eventData.pointerEnter.transform as RectTransform;
        }

        var     rt = m_DraggingIcons[eventData.pointerId].GetComponent <RectTransform>();
        Vector3 globalMousePos;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_DraggingPlanes[eventData.pointerId], eventData.position, eventData.pressEventCamera, out globalMousePos))
        {
            rt.position = globalMousePos;
            //rt.rotation = m_DraggingPlanes[eventData.pointerId].rotation;
            rt.rotation = gameObject.GetComponent <RectTransform>().rotation;
        }
    }
    //вызывается, когда начинается перемещение (палец жамает на экран)
    public void OnBeginDrag(PointerEventData eventData)
    {
        //включить thumb
        thumb.gameObject.SetActive(true);



        //зафиксировать мировые координаты, (где палец жамнул на экран) откуда начато перемещение
        Vector3 worldPoint = new Vector3();

        RectTransformUtility.ScreenPointToWorldPointInRectangle(this.transform as RectTransform, eventData.position, eventData.enterEventCamera, out worldPoint);

        //переместить VirtualJoystick (this) в позицию, (куда палец жамнул на экран) откуда начато перемещение
        this.GetComponent <RectTransform>().position = worldPoint;

        thumb.localPosition = originalPosition;
    }
Esempio n. 17
0
 public void ExplodeTask()
 {
     string[] parts = task.text.Split(' ');
     task.text = string.Empty;
     for (int i = 0; i < parts.Length; i++)
     {
         Vector3 meh = camControl.WorldToUI(task.transform.position - Vector3.right * 0.5f + Vector3.right * i);
         Vector3 pos = Vector3.zero;
         RectTransformUtility.ScreenPointToWorldPointInRectangle(task.rectTransform, meh, camControl.uiCamera, out pos);
         GameObject go   = NewText(parts [i], pos, task);
         Rigidbody  body = go.AddComponent <Rigidbody> ();
         body.AddExplosionForce(50, task.transform.position, 5);
         Vector3 torque = new Vector3(0, 0, -(pos.x - task.transform.position.x) * 100);
         body.AddTorque(torque);
         Destroy(go, 1.5f);
     }
 }
Esempio n. 18
0
        public void OnPointerDown(PointerEventData eventData)
        {
            joystickHeld = true;

            if (isDynamicJoystick)
            {
                pointerInitialPos = Vector2.zero;

                Vector3 joystickPos;
                RectTransformUtility.ScreenPointToWorldPointInRectangle(dynamicJoystickMovementArea, eventData.position, eventData.pressEventCamera, out joystickPos);
                joystickTR.position = joystickPos;
            }
            else
            {
                RectTransformUtility.ScreenPointToLocalPointInRectangle(joystickTR, eventData.position, eventData.pressEventCamera, out pointerInitialPos);
            }
        }
Esempio n. 19
0
        protected virtual void TranslateUI(float pinchScale, Vector2 pinchScreenCenter)
        {
            // Положение экрана трансформации
            var screenPoint = RectTransformUtility.WorldToScreenPoint(Camera, transform.position);

            // Отодвиньте положение экрана от контрольной точки на основе scale
            screenPoint.x = pinchScreenCenter.x + (screenPoint.x - pinchScreenCenter.x) * pinchScale;
            screenPoint.y = pinchScreenCenter.y + (screenPoint.y - pinchScreenCenter.y) * pinchScale;

            // Конвертировать обратно в мировое пространство
            var worldPoint = default(Vector3);

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(transform.parent as RectTransform, screenPoint, Camera, out worldPoint) == true)
            {
                transform.position = worldPoint;
            }
        }
Esempio n. 20
0
        // Use this for initialization
        void Start()
        {
            if (m_cameraPlane == null)
            {
                //See if camera already has one
                m_cameraPlane = Camera.main.gameObject.GetComponentInChildren <RectTransform>();
                //If it doesnt have one add one
                if (m_cameraPlane == null)
                {
                    m_cameraPlane = Instantiate <GameObject>(m_worldCanvas, Camera.main.transform).GetComponent <RectTransform>();
                }
            }

            m_startPos = transform.position;
            //RectTransformUtility.ScreenPointToWorldPointInRectangle(canvRect, (Vector2)canvRect.position, Camera.main, out m_targetPos);
            RectTransformUtility.ScreenPointToWorldPointInRectangle(m_cameraPlane, (Vector2)m_UITargetRect.position, Camera.main, out m_targetPos);
        }
Esempio n. 21
0
    void Update()
    {
        Vector3 mousePos;

        RectTransformUtility.ScreenPointToWorldPointInRectangle(UGUICanvas, new Vector2(Input.mousePosition.x, Input.mousePosition.y), mainCamera, out mousePos);
        float z;

        if (mousePos.x > transform.position.x)
        {
            z = -Vector3.Angle(Vector3.up, mousePos - transform.position);
        }
        else
        {
            z = Vector3.Angle(Vector3.up, mousePos - transform.position);
        }
        transform.localRotation = Quaternion.Euler(0, 0, z);
    }
Esempio n. 22
0
    // Вызывается, когда начинается перемещение
    public void OnBeginDrag(PointerEventData eventData)
    {
        Debug.Log("Палец на джойстике");
        // Сделать площадку видимой
        thumb.gameObject.SetActive(true);

        //Зафиксировать мировые координаты, откуда начато перемещение
        Vector3 worldPoint = new Vector3();

        RectTransformUtility.ScreenPointToWorldPointInRectangle(this.transform as RectTransform, eventData.position, eventData.enterEventCamera, out worldPoint);

        // Поместить джойстик в эту позицию
        this.GetComponent <RectTransform>().position = worldPoint;

        // Поместить площадку в исходную позицию относительно джойстика
        thumb.localPosition = originalThumbPosition;
    }
        private Vector2 GetJoystickOffset(PointerEventData eventData)
        {
            Vector3 globalHandle;

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(transform as RectTransform, eventData.position, eventData.pressEventCamera, out globalHandle))
            {
                handle.position = globalHandle;
            }
            var handleOffset = handle.anchoredPosition;

            if (handleOffset.magnitude > radius)
            {
                handleOffset            = handleOffset.normalized * radius;
                handle.anchoredPosition = handleOffset;
            }
            return(handleOffset);
        }
Esempio n. 24
0
    //-------------------------------------------------------------
    //! 座標更新
    //-------------------------------------------------------------
    protected void SetDraggedPosition(PointerEventData _eventData)
    {
        if (m_dragOnSurfaces && _eventData.pointerEnter != null && _eventData.pointerEnter.transform as RectTransform != null)
        {
            m_draggingPlane = _eventData.pointerEnter.transform as RectTransform;
        }

        RectTransform rt = m_draggingIcon.GetComponent <RectTransform>();
        Vector3       globalMousePos;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_draggingPlane,
                                                                    _eventData.position, _eventData.pressEventCamera, out globalMousePos))
        {
            rt.position = globalMousePos;
            rt.rotation = m_draggingPlane.rotation;
        }
    }
Esempio n. 25
0
    void Update()
    {
        if (Camera.main == null || m_Target == null)
        {
            return;
        }

        //世界左边点 转换成视口坐标
        Vector3 screenPos = Camera.main.WorldToScreenPoint(m_Target.position);
        //转换成UI摄像机的世界坐标
        Vector3 pos;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_RectTrans, screenPos, UI_Camera.Instance.Camera, out pos))
        {
            transform.position = pos;
        }
    }
Esempio n. 26
0
 public void OnDrag(PointerEventData eventData)
 {
     //if (-365 < rt.anchoredPosition.x && rt.anchoredPosition.x < 365)
     //{
     //    if (rt.anchoredPosition.y < 165 && rt.anchoredPosition.y > -165)
     //    {
     // 将屏幕空间上的点转换为位于给定RectTransform平面上的世界空间中的位置
     if (RectTransformUtility.ScreenPointToWorldPointInRectangle(rt, eventData.position, eventData.pressEventCamera, out Vector3 globalMousePos))
     {
         // 设置拖拽范围
         //Debug.Log("拖拽中");
         rt.position = DragRangeLimit(globalMousePos + offset);
         //rt.position = offset + globalMousePos;
     }
     //    }
     //}
 }
    private void SetDraggedPosition(PointerEventData data)
    {
        // get 3d position from pointer data.
        if (dragOnSurfaces && data.pointerEnter != null && data.pointerEnter.transform as RectTransform != null)
        {
            m_DraggingPlane = data.pointerEnter.transform as RectTransform;
        }

        var     rt = m_DraggingIcon.GetComponent <RectTransform>();
        Vector3 globalMousePos;

        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_DraggingPlane, data.position, data.pressEventCamera, out globalMousePos))
        {
            rt.position = globalMousePos;
            rt.rotation = m_DraggingPlane.rotation;
        }
    }
Esempio n. 28
0
        protected virtual void TranslateUI(float pinchScale, Vector2 pinchScreenCenter)
        {
            // posição da tela da transformação
            var screenPoint = RectTransformUtility.WorldToScreenPoint(Camera, transform.position);

            // afasta a posição da tela do ponto de referência com base na escala
            screenPoint.x = pinchScreenCenter.x + (screenPoint.x - pinchScreenCenter.x) * pinchScale;
            screenPoint.y = pinchScreenCenter.y + (screenPoint.y - pinchScreenCenter.y) * pinchScale;

            // converte de volta ao espaço mundial
            var worldPoint = default(Vector3);

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(transform.parent as RectTransform, screenPoint, Camera, out worldPoint) == true)
            {
                transform.position = worldPoint;
            }
        }
Esempio n. 29
0
    void Update()
    {
        Vector3 vector3;

        RectTransformUtility.ScreenPointToWorldPointInRectangle(RectTransform, new Vector2
                                                                (
                                                                    Input.mousePosition.x,
                                                                    Input.mousePosition.y
                                                                ), Camera, out vector3);

        var z = Vector3.Angle(Vector3.up, vector3 - transform.position) *
                (
            vector3.x > transform.position.x ? -1 : 1
                );

        transform.localRotation = Quaternion.Euler(0, 0, z);
    }
Esempio n. 30
0
        private void SetDraggedPosition(PointerEventData _eventData)
        {
            eventData = _eventData;
            if (eventData.pointerEnter != null && eventData.pointerEnter.transform as RectTransform != null)
            {
                draggingPlanes_[eventData.pointerId] = eventData.pointerEnter.transform as RectTransform;
            }

            var     rt = draggingImage_[eventData.pointerId].GetComponent <RectTransform>();
            Vector3 globalMousePos;

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(draggingPlanes_[eventData.pointerId], eventData.position, eventData.pressEventCamera, out globalMousePos))
            {
                rt.position = globalMousePos;
                rt.rotation = draggingPlanes_[eventData.pointerId].rotation;
            }
        }