Пример #1
0
        public void ControlMovement(bool visible, enMotionType motionType, enScreenSides side, float duration, EquationsParameters easingParams, float edgeGap = 0.25f, Vector3 customPosition = new Vector3(), bool customLocal = false)
        {
            Vector3 outPos = outOfScreenPos;

            if (side != HidingPosition || edgeGap != EdgeGap || (side == enScreenSides.Custom && customLocal != LocalCustomPosition))
            {
                outPos = GetHidingPosition(side, edgeGap, customPosition, customLocal);
            }

            Vector3 ePos = visible ? MovementSection.startVectorValue : outPos;
            Vector3 sPos = selfRectTransform.position;

            if (!gameObject.activeInHierarchy)
            {
                selfRectTransform.position = ePos;
                return;
            }

            if (MovementSection.motionEnum != null)
            {
                StopCoroutine(MovementSection.motionEnum);
                MovementSection.motionEnum = null;
            }

            MovementSection.motionEnum = VectorMotion((v) => {
                selfRectTransform.position = v;
            }, sPos, ePos, MovementSection.HideAfter, MovementSection.ShowAfter,
                                                      duration, easingParams, motionType);
            StartCoroutine(MovementSection.motionEnum);
        }
Пример #2
0
        Vector3 GetHidingPosition(enScreenSides hidingPos, float edgeGap, Vector2 customPosition, bool customLocal)
        {
            Vector3 pos              = new Vector3();
            float   y                = 0;
            float   x                = 0;
            Vector2 distanceToEdge   = new Vector2(selfRectTransform.pivot.x, selfRectTransform.pivot.y);
            Vector3 originalPosition = MovementSection.startVectorValue;

            switch (hidingPos)
            {
            case enScreenSides.Top:
                y   = parentCanvasRectTransform.position.y + canvasHalfHeight + selfRectTransformHeight * (distanceToEdge.y + edgeGap);
                pos = new Vector3(originalPosition.x, y, originalPosition.z);
                break;

            case enScreenSides.Bottom:
                y   = parentCanvasRectTransform.position.y - canvasHalfHeight - selfRectTransformHeight * (1 - distanceToEdge.y + edgeGap);
                pos = new Vector3(originalPosition.x, y, originalPosition.z);
                break;

            case enScreenSides.Left:
                x   = parentCanvasRectTransform.position.x - canvasHalfWidth - selfRectTransformWidth * (1 - distanceToEdge.x + edgeGap);
                pos = new Vector3(x, originalPosition.y, originalPosition.z);
                break;

            case enScreenSides.Right:
                x   = parentCanvasRectTransform.position.x + canvasHalfWidth + selfRectTransformWidth * (distanceToEdge.x + edgeGap);
                pos = new Vector3(x, originalPosition.y, originalPosition.z);
                break;

            case enScreenSides.TopLeftCorner:
                y   = parentCanvasRectTransform.position.y + canvasHalfHeight + selfRectTransformHeight * (distanceToEdge.y + edgeGap);
                x   = parentCanvasRectTransform.position.x - canvasHalfWidth - selfRectTransformWidth * (1 - distanceToEdge.x + edgeGap);
                pos = new Vector3(x, y, originalPosition.z);
                break;

            case enScreenSides.TopRightCorner:
                y   = parentCanvasRectTransform.position.y + canvasHalfHeight + selfRectTransformHeight * (distanceToEdge.y + edgeGap);
                x   = parentCanvasRectTransform.position.x + canvasHalfWidth + selfRectTransformWidth * (distanceToEdge.x + edgeGap);
                pos = new Vector3(x, y, originalPosition.z);
                break;

            case enScreenSides.BotLeftCorner:
                y   = parentCanvasRectTransform.position.y - canvasHalfHeight - selfRectTransformHeight * (1 - distanceToEdge.y + edgeGap);
                x   = parentCanvasRectTransform.position.x - canvasHalfWidth - selfRectTransformWidth * (1 - distanceToEdge.x + edgeGap);
                pos = new Vector3(x, y, originalPosition.z);
                break;

            case enScreenSides.BotRightCorner:
                y   = parentCanvasRectTransform.position.y - canvasHalfHeight - selfRectTransformHeight * (1 - distanceToEdge.y + edgeGap);
                x   = parentCanvasRectTransform.position.x + canvasHalfWidth + selfRectTransformWidth * (distanceToEdge.x + edgeGap);
                pos = new Vector3(x, y, originalPosition.z);
                break;

            case enScreenSides.Custom:
                Vector3 holderPos;
                float   holderHalfWidth  = 0;
                float   holderHalfHeight = 0;

                if (customLocal && directParentRectTransform)
                {
                    holderPos        = directParentRectTransform.position;
                    holderHalfWidth  = directParentHalfWidth;
                    holderHalfHeight = directParentHalfHeight;
                }
                else
                {
                    holderPos        = parentCanvasRectTransform.position;
                    holderHalfWidth  = canvasHalfWidth;
                    holderHalfHeight = canvasHalfHeight;
                }
                pos = new Vector3(
                    holderPos.x + (customPosition.x - 0.5f) * holderHalfWidth * 2,
                    holderPos.y + (customPosition.y - 0.5f) * holderHalfHeight * 2, originalPosition.z);
                break;
            }
            return(pos);
        }