Exemple #1
0
    public void SetArrowRot(ArrowRot rot)
    {
        if (mArrowRot == rot)
        {
            return;
        }
        mArrowRot = rot;
        float rotAngle = 0.0f;

        switch (rot)
        {
        case ArrowRot.ArrowRot_UP:
            rotAngle = 180.0f;
            break;

        case ArrowRot.ArrowRot_DOWN:
            rotAngle = 0.0f;
            break;

        case ArrowRot.ArrowRot_LEFT:
            rotAngle = 270.0f;
            break;

        case ArrowRot.ArrowRot_RIGHT:
            rotAngle = 90.0f;
            break;
        }
        if (Mathf.Abs((mArrow.transform.eulerAngles.z - rotAngle)) > 0.00001f)
        {
            Quaternion qua = Quaternion.Euler(new Vector3(0.0f, 0.0f, rotAngle));
            mArrow.transform.rotation = qua;
        }
    }
Exemple #2
0
    public static void UpdateUIPos(GameObject control, ArrowRot rot, ArrawUI arraw)
    {
        var pos = GetControlPos(control);

        //计算二维坐标的时候 必须加入SpectRatio 做屏幕适应
        float spectRatio = WindowManager.GetSpectRatio();
        int   ctrlWidth  = GetControlWidth(control);
        int   ctrlHeight = GetControlHeight(control);

        if (rot == ArrowRot.ArrowRot_Invaild)
        {
            //控件在屏幕左边
            if (pos.x < Screen.width / 2)
            {
                rot = ArrowRot.ArrowRot_RIGHT;
            }
            else
            {
                rot = ArrowRot.ArrowRot_LEFT;
            }
        }


        Vector2 arrowPos = new Vector2();

        if (rot == ArrowRot.ArrowRot_LEFT)
        {
            arrowPos.y = pos.y;
            arrowPos.x = pos.x - (ctrlWidth / 2 + arraw.GetArrowWidth() / 2) / spectRatio;
        }
        else if (rot == ArrowRot.ArrowRot_RIGHT)
        {
            arrowPos.y = pos.y;
            arrowPos.x = pos.x + (ctrlWidth / 2 + arraw.GetArrowWidth() / 2) / spectRatio;
        }
        else if (rot == ArrowRot.ArrowRot_UP)
        {
            arrowPos.x = pos.x;
            arrowPos.y = pos.y + (ctrlHeight / 2 + arraw.GetArrowHeight() / 2) / spectRatio;
        }
        else if (rot == ArrowRot.ArrowRot_DOWN)
        {
            arrowPos.x = pos.x;
            arrowPos.y = pos.y - (ctrlHeight / 2 + arraw.GetArrowHeight() / 2) / spectRatio;
        }

        arraw.SetArrowRot(rot);
        arraw.SetEffectPos(WindowManager.current2DCamera.ScreenToWorldPoint(pos));
        arraw.SetEffectSize(ctrlWidth, ctrlHeight);
        arraw.SetArrowPos(WindowManager.current2DCamera.ScreenToWorldPoint(arrowPos));
    }