Exemplo n.º 1
0
    private bool GetPositionsOnPaintView(ref Vector3 canvasPos, ref Vector3 uvPos)
    {
        var m_PointerEventData = new PointerEventData(m_EventSystem);

        m_PointerEventData.position = Input.mousePosition;

        List <RaycastResult> results = new List <RaycastResult>();

        m_Raycaster.Raycast(m_PointerEventData, results);

        foreach (RaycastResult result in results)
        {
            if (result.gameObject.name == StratchCover.gameObject.name)
            {
                Vector2 localPos = Vector2.zero;

                localPos = RectTransformUtility.PixelAdjustPoint(result.screenPosition, StratchCover,
                                                                 GetComponent <Canvas>());

                canvasPos = localPos;

                Vector2 posIn;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle(StratchCover, mousePosition, null, out posIn))
                {
                    var X = (-StratchCover.rect.width / 2 - posIn.x) / StratchCover.rect.width;
                    var Y = (-StratchCover.rect.height / 2 - posIn.y) / StratchCover.rect.height;
                    uvPos = new Vector3((X * -1), (Y * -1), 0);
                }

                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 2
0
 void Start()
 {
     //RectTransformUtility.FlipLayoutAxes(GetComponent<RectTransform>(), false, false);
     //RectTransformUtility.FlipLayoutOnAxis(GetComponent<RectTransform>(), 1, true, true);
     //RectTransformUtility.PixelAdjustRect(GetComponent<RectTransform>(), GameObject.Find("Canvas").GetComponent<Canvas>());
     RectTransformUtility.PixelAdjustPoint(GetComponent <RectTransform>().localPosition, target, GameObject.Find("Canvas").GetComponent <Canvas>());
 }
Exemplo n.º 3
0
    void updateSelectInfo()
    {
        var c_point     = Camera.main.WorldToScreenPoint(m_CenterPoint);
        var centerPoint = new Vector2(c_point.x, c_point.y);

        centerPoint = RectTransformUtility.PixelAdjustPoint(centerPoint, transform, m_Canvas);

        foreach (var item in m_SceneInfo)
        {
            var _point      = Camera.main.WorldToScreenPoint(item.pointPosition);
            var screenPoint = new Vector2(_point.x, _point.y);
            screenPoint = RectTransformUtility.PixelAdjustPoint(screenPoint, item.bindBtn.transform, m_Canvas);

            var depth = _point.z;

            var offset = screenPoint - centerPoint;
            offset  = offset.normalized;
            offset *= m_BoxSize;
            // offset = Vector2.Lerp(-m_BoxSize, m_BoxSize, offset.x);
            // 分层
            offset.x += (offset.x < 0 ? -m_AxisXOffset : m_AxisXOffset);

            var current = item.bindBtn.GetComponent <RectTransform>();
            current.localPosition = Vector2.Lerp(current.localPosition, offset, 0.1f);
        }
    }
Exemplo n.º 4
0
 public Vector2 PixelAdjustPoint(Vector2 point)
 {
     if (!canvas || !canvas.pixelPerfect)
     {
         return(point);
     }
     return(RectTransformUtility.PixelAdjustPoint(point, base.transform, canvas));
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// <para>
 /// Adjusts the given pixel to be pixel perfect.
 /// </para>
 ///
 /// </summary>
 /// <param name="point">Local space point.</param>
 /// <returns>
 ///
 /// <para>
 /// Pixel perfect adjusted point.
 /// </para>
 ///
 /// </returns>
 public Vector2 PixelAdjustPoint(Vector2 point)
 {
     if (!(bool)((UnityEngine.Object) this.canvas) || !this.canvas.pixelPerfect)
     {
         return(point);
     }
     return(RectTransformUtility.PixelAdjustPoint(point, this.transform, this.canvas));
 }
Exemplo n.º 6
0
 public Vector2 PixelAdjustPoint(Vector2 point)
 {
     if (!canvas || canvas.renderMode == RenderMode.WorldSpace || canvas.scaleFactor == 0f || !canvas.pixelPerfect)
     {
         return(point);
     }
     return(RectTransformUtility.PixelAdjustPoint(point, base.transform, canvas));
 }
Exemplo n.º 7
0
 public Vector2 PixelAdjustPoint(Vector2 point)
 {
     if ((this.canvas != null) && this.canvas.pixelPerfect)
     {
         return(RectTransformUtility.PixelAdjustPoint(point, base.transform, this.canvas));
     }
     return(point);
 }
    static int PixelAdjustPoint(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        Vector2   arg0 = LuaScriptMgr.GetVector2(L, 1);
        Transform arg1 = (Transform)LuaScriptMgr.GetUnityObject(L, 2, typeof(Transform));
        Canvas    arg2 = (Canvas)LuaScriptMgr.GetUnityObject(L, 3, typeof(Canvas));
        Vector2   o    = RectTransformUtility.PixelAdjustPoint(arg0, arg1, arg2);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Exemplo n.º 9
0
    public bool IsAlphaPoint(PointerEventData eventData)
    {
        Vector2 localCursor;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, eventData.position, eventData.pressEventCamera, out localCursor);
        Vector2 pos = RectTransformUtility.PixelAdjustPoint(localCursor, rectTransform, canvas);

        int x = (int)(pos.x + image.sprite.texture.width * rectTransform.pivot.x);
        int y = (int)(pos.y + image.sprite.texture.height * rectTransform.pivot.y);

        return(image.sprite.texture.GetPixel(x, y).a > 0);
    }
Exemplo n.º 10
0
        public Vector3 GetPosition(PointerEventData eventData)
        {
            Vector2 pos;

            pos = eventData.position;
            if (_canvas.renderMode == RenderMode.ScreenSpaceOverlay)
            {
                return(RectTransformUtility.PixelAdjustPoint(pos, transform, _canvas));
            }
            else
            {
                return(_canvas.worldCamera.ScreenToWorldPoint(eventData.position));
            }
        }
Exemplo n.º 11
0
        public Vector2 PixelAdjustPoint(Vector2 point)
        {
            Vector2 result;

            if (!this.canvas || this.canvas.renderMode == RenderMode.WorldSpace || this.canvas.scaleFactor == 0f || !this.canvas.pixelPerfect)
            {
                result = point;
            }
            else
            {
                result = RectTransformUtility.PixelAdjustPoint(point, base.transform, this.canvas);
            }
            return(result);
        }
Exemplo n.º 12
0
    Vector3 ComputeTargetPosition()
    {
        Vector2 canvasPosition = canvas.GetComponent <RectTransform>().anchoredPosition
                                 + reticleTransform.anchoredPosition;
        Vector2    pixelPosition = RectTransformUtility.PixelAdjustPoint(canvasPosition, transform, canvas);
        float      distance      = Vector3.Distance(player.position, Camera.main.transform.position);
        Ray        ray           = Camera.main.ScreenPointToRay(new Vector3(pixelPosition.x, pixelPosition.y, 0.0f));
        RaycastHit hit;

        Physics.Raycast(ray, out hit);
        return(new Vector3(
                   hit.point.x,
                   player.position.y,
                   player.position.z
                   ));
    }
Exemplo n.º 13
0
        public static Vector3 CanvasToWorldPoint(Transform tr)
        {
            Vector3 zero = Vector3.zero;
            Canvas  componentInParent = tr.GetComponentInParent <Canvas>();
            bool    flag = componentInParent == null;
            Vector3 result;

            if (flag)
            {
                result = Vector3.zero;
            }
            else
            {
                RectTransform component = componentInParent.GetComponent <RectTransform>();
                Vector2       vector    = RectTransformUtility.PixelAdjustPoint(tr.position, tr, componentInParent);
                RectTransformUtility.ScreenPointToWorldPointInRectangle(component, vector, Camera.main, out zero);
                result = zero;
            }
            return(result);
        }
    public static int PixelAdjustPoint_s(IntPtr l)
    {
        int result;

        try
        {
            Vector2 point;
            LuaObject.checkType(l, 1, out point);
            Transform elementTransform;
            LuaObject.checkType <Transform>(l, 2, out elementTransform);
            Canvas canvas;
            LuaObject.checkType <Canvas>(l, 3, out canvas);
            Vector2 o = RectTransformUtility.PixelAdjustPoint(point, elementTransform, canvas);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, o);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
 void DoAction()
 {
     pixelPoint.Value = RectTransformUtility.PixelAdjustPoint(screenPoint.Value, _rt, _canvas);
 }
    void FixedUpdate()
    {
        if (startDrawing)
        {
            Vector3 Dist            = mousePos - Input.mousePosition;
            float   Distance_SqrMag = Dist.sqrMagnitude;

            if (Distance_SqrMag > 1000f)
            {
                //limitar a area de desenho
                //limit draw area
                if (mousePos.x > RectTransformUtility.PixelAdjustPoint(limitTopLeft.position, limitTopLeft, canvasScenario).x&& mousePos.x < RectTransformUtility.PixelAdjustPoint(limitBottomRight.position, limitBottomRight, canvasScenario).x&& mousePos.y < RectTransformUtility.PixelAdjustPoint(limitTopLeft.position, limitTopLeft, canvasScenario).y&& mousePos.y > RectTransformUtility.PixelAdjustPoint(limitBottomRight.position, limitBottomRight, canvasScenario).y)
                {
                    //Coloca a posição para a linha
                    // Set the position for the line
                    lR.SetPosition(currentIndex, cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Mathf.Round(Input.mousePosition.z) + 10f)));

                    if (lastInstantiated_Collider != null)
                    {
                        //Cria a linha
                        //Creates line1
                        Vector3 CurLinePos = lR.GetPosition(currentIndex);
                        lastInstantiated_Collider.gameObject.SetActive(true);
                        lastInstantiated_Collider.LookAt(CurLinePos);

                        if (lastInstantiated_Collider.rotation.y == 0)
                        {
                            lastInstantiated_Collider.eulerAngles = new Vector3(lastInstantiated_Collider.rotation.eulerAngles.x, 90, lastInstantiated_Collider.rotation.eulerAngles.z);
                        }
                        //Collider em volta da linha
                        //Collider around the line
                        lastInstantiated_Collider.localScale = new Vector3(lastInstantiated_Collider.localScale.x, lastInstantiated_Collider.localScale.y, Vector3.Distance(lastInstantiated_Collider.position, CurLinePos) * 1.1f);
                    }

                    if (lastInstantiated_Collider != null)
                    {
                        //Cria a linha2
                        //Creates line2
                        Vector3 CurLinePos = lR.GetPosition(currentIndex);
                        lastInstantiated_Collider2.gameObject.SetActive(true);
                        lastInstantiated_Collider2.LookAt(CurLinePos);

                        if (lastInstantiated_Collider2.rotation.y == 0)
                        {
                            lastInstantiated_Collider2.eulerAngles = new Vector3(lastInstantiated_Collider2.rotation.eulerAngles.x, 90, lastInstantiated_Collider2.rotation.eulerAngles.z);
                        }
                        //Collider em volta da linha2
                        //collider around the line
                        lastInstantiated_Collider2.localScale = new Vector3(lastInstantiated_Collider2.localScale.x, lastInstantiated_Collider2.localScale.y, Vector3.Distance(lastInstantiated_Collider2.position, CurLinePos) * 1.1f);
                    }
                    //Coloca o pivot no início da linha, e instância formas em 3D (se usar algum prefab em 3d) para cada nova posição do mouse
                    //Put the pivot on the line start, and instantiate new 3D forms for every new mouse position
                    lineGO2.transform.position = lR.GetPosition(0);
                    lineGO.transform.position  = lR.GetPosition(0);
                    LastInstantiateCollider();
                    LastInstantiateCollider2();
                    mousePos = Input.mousePosition;
                    currentIndex++;
                    lR.positionCount = currentIndex + 1;
                    lR.SetPosition(currentIndex, cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z + 10f)));
                }
            }
        }
    }
 protected override void OnExecute()
 {
     pixelPoint.value = RectTransformUtility.PixelAdjustPoint(screenPoint.value, agent, canvas.value);
     EndAction();
 }
Exemplo n.º 18
0
 private Vector3 Snap(Vector3 p)
 {
     return(RectTransformUtility.PixelAdjustPoint(p, transform, canvas));
 }
Exemplo n.º 19
0
        public static bool ContainsRect(this Canvas canvas, Transform transform)
        {
            var position = RectTransformUtility.PixelAdjustPoint(transform.position, transform, canvas);

            return(canvas.pixelRect.Contains(position));
        }