Пример #1
0
        void Init(GameObject target)
        {
            TargetObject = target;
            TargetTrans  = target.transform;
            var pos = TargetTrans.position;

            TargetObjOldPosX = pos.x;
            TargetObjOldPosY = pos.y;
            var scale = TargetTrans.localScale;

            TargetObjOldScaleX = scale.x;
            TargetObjOldScaleY = scale.y;

            Bounds = UGUIMath.CalculateAbsoluteBounds(TargetTrans.GetComponent <RectTransform>());
        }
Пример #2
0
        /// <summary>
        /// Target的位置发生变化时,更新引导的箭头
        /// </summary>
        private void CheckTargetObjPosChange()
        {
            var new_pos   = TargetTrans.position;
            var new_scale = TargetTrans.localScale;

            if (Mathf.Abs(new_pos.x - TargetObjOldPosX) < MIN_DIFF && Mathf.Abs(new_pos.y - TargetObjOldPosY) <= MIN_DIFF &&
                Mathf.Abs(new_scale.x - TargetObjOldScaleX) < MIN_DIFF && Mathf.Abs(new_scale.y - TargetObjOldScaleY) <= MIN_DIFF)
            {
                return;
            }

            Bounds           = UGUIMath.CalculateAbsoluteBounds(TargetTrans.GetComponent <RectTransform>());
            TargetObjOldPosX = new_pos.x;
            TargetObjOldPosY = new_pos.y;

            TargetObjOldScaleX = new_scale.x;
            TargetObjOldScaleY = new_scale.y;

            if (CopyObj != null)
            {
                // 可能traget_trans的父亲节点有缩放
                var rect_corner = new Vector3[4];
                CopyTrans.GetComponent <RectTransform>().GetWorldCorners(rect_corner);
                float copy_rect_size_x = rect_corner[2].x - rect_corner[0].x;

                TargetTrans.GetComponent <RectTransform>().GetWorldCorners(rect_corner);
                float target_size_x = rect_corner[2].x - rect_corner[0].x;

                float scale = 1;
                if (copy_rect_size_x != 0)
                {
                    scale = target_size_x / copy_rect_size_x;
                }
                Vector3 ori_scale = CopyTrans.localScale;
                CopyTrans.localScale = new Vector3(ori_scale.x * scale, ori_scale.y * scale, ori_scale.z * scale);
            }

            Wnd.ResetArrowTips();
        }