Ejemplo n.º 1
0
        private void RefreshPlayTeamItem(Transform tran, MiniMapTeamPlayInfo data)
        {
            //控制位置和方向
            {
                var direction = tran.Find("direction");
                if (direction == null)
                {
                    return;
                }
                var directRT = direction.GetComponent <RectTransform>();
                var tranRT   = tran.GetComponent <RectTransform>();

                var offset = new Vector2(tranRT.sizeDelta.y + directRT.sizeDelta.y, tranRT.sizeDelta.y + directRT.sizeDelta.y) / (2 * rate);
                var result = UIUtils.MathUtil.IsInSquare(PlayRefePosByRice, MaxMapRepresentWHByRice, MaxMapRepresentWHByRice, offset, true, data.Pos.ShiftedUIVector2());
                tran.GetComponent <RectTransform>().anchoredPosition = playRefePosByPixel + result.ContactPoint * rate;

                if (!result.IsContact)
                {
                    UIUtils.SetActive(direction, false);
                    UIUtils.SetActive(tran, true);
                }
                else
                {
                    UIUtils.SetActive(tran, false);
                    UIUtils.SetActive(direction, false);
//                    {
//                        Vector2 fromVector = new Vector2(0, 1);
//                        Vector2 toVector = tran.GetComponent<RectTransform>().anchoredPosition.normalized;
//
//                        float angle = UnityEngine.Vector2.Angle(fromVector, toVector); //求出两向量之间的夹角
//                        UnityEngine.Vector3 normal = UnityEngine.Vector3.Cross(fromVector, toVector);//叉乘求出法线向量
//                        if (normal.z < 0)
//                        {
//                            angle = 360 - angle;
//                        }
//                        direction.localEulerAngles = new UnityEngine.Vector3(0, 0, (angle + 180) % 360);
//                    }
                }
            }

            //编号和编号背景色
            playMarkUtil.UpdatePlayNumAndColor(tran, ref PlayRefePosByRice, data, false);

            //控制朝向
            playMarkUtil.UpdatePlayFaceDirection(tran, data);
        }