示例#1
0
        Vector3 GetRelateeLocalPos(RelativeLocationDirection direction =
                                   RelativeLocationDirection.right)
        {
            Vector3 delta = Vector3.zero;

            switch (direction)
            {
            case RelativeLocationDirection.left:
                delta.x -= this.relatee.GetSelfWidth() / 2;
                break;

            case RelativeLocationDirection.right:
                delta.x += this.relatee.GetSelfWidth() / 2;
                break;

            case RelativeLocationDirection.center:
                break;

            case RelativeLocationDirection.top:
                delta.y += this.relatee.GetSelfHeight() / 2;
                break;

            case RelativeLocationDirection.bottom:
                delta.y -= this.relatee.GetSelfHeight() / 2;
                break;

            default:
                break;
            }
            return(relatee.localPosition + delta);
        }
示例#2
0
        Vector3 AdjustRelatorLocalPos(Vector3 localPos, RelativeLocationDirection
                                      direction = RelativeLocationDirection.right)
        {
            Vector3 delta = Vector3.zero;

            switch (direction)
            {
            case RelativeLocationDirection.left:
                delta.x -= selfRectrans.GetSelfWidth() / 2;
                break;

            case RelativeLocationDirection.right:
                delta.x += selfRectrans.GetSelfWidth() / 2;
                break;

            case RelativeLocationDirection.center:
                break;

            case RelativeLocationDirection.top:
                delta.y += selfRectrans.GetSelfHeight() / 2;
                break;

            case RelativeLocationDirection.bottom:
                delta.y -= selfRectrans.GetSelfHeight() / 2;
                break;

            default:
                break;
            }
            return(localPos + delta);
        }
示例#3
0
        public Vector3 FixLocalPosition(RectTransform relatee = null,
                                        RelativeLocationDirection direction = RelativeLocationDirection.right)
        {
            this.relatee = relatee ?? this.relatee;
            Vector3 result = GetRelateeLocalPos(direction);

            result = this.relatee.LocalPosToCenterPos(result);
            result = this.relatee.parent.TransformPoint(result);

            result = transform.parent.InverseTransformPoint(result);
            result = selfRectrans.CenterPosToLocalPos(result);
            result = AdjustRelatorLocalPos(result, direction);
            selfRectrans.localPosition = result;

            return(result);
        }