Ejemplo n.º 1
0
    public override void ResetAtTheEnd()
    {
        base.ResetAtTheEnd();


        Vector2 offsetMin        = RectTransform.offsetMin;
        Vector2 offsetMax        = RectTransform.offsetMax;
        Vector2 anchoredPosition = RectTransform.anchoredPosition;

        if (AnchorTool.IsStretchedHorizontally(RectTransform) && mode == Mode.Auto)
        {
            offsetMin.x        = offsetMinX.dst;
            offsetMax.x        = -offsetMaxX.dst;
            anchoredPosition.x = offsetMin.x * 0.5f + offsetMax.x * 0.5f;
        }
        else
        {
            anchoredPosition.x = posX.dst;
        }

        if (AnchorTool.IsStretchedVertically(RectTransform) && mode == Mode.Auto)
        {
            offsetMin.y        = offsetMinY.dst;
            offsetMax.y        = -offsetMaxY.dst;
            anchoredPosition.y = offsetMin.y * 0.5f + offsetMax.y * 0.5f;
        }
        else
        {
            anchoredPosition.y = posY.dst;
        }

        RectTransform.offsetMin        = offsetMin;
        RectTransform.offsetMax        = offsetMax;
        RectTransform.anchoredPosition = anchoredPosition;
    }
Ejemplo n.º 2
0
            public static void Set(RectTransform rectTransform, float left, float right, float top, float bottom)
            {
                Vector2 offsetMin        = rectTransform.offsetMin;
                Vector2 offsetMax        = rectTransform.offsetMax;
                Vector2 anchoredPosition = rectTransform.anchoredPosition;

                if (AnchorTool.IsStretchedHorizontally(rectTransform))
                {
                    offsetMin.x        = left;
                    offsetMax.x        = -right;
                    anchoredPosition.x = offsetMin.x * 0.5f + offsetMax.x * 0.5f;
                }
                else
                {
                    Debug.LogWarning(rectTransform.gameObject + " is not horizontally stretched");
                }

                if (AnchorTool.IsStretchedVertically(rectTransform))
                {
                    offsetMin.y        = bottom;
                    offsetMax.y        = -top;
                    anchoredPosition.y = offsetMin.y * 0.5f + offsetMax.y * 0.5f;
                }
                else
                {
                    Debug.LogWarning(rectTransform.gameObject + " is not vertically stretched");
                }

                rectTransform.offsetMin        = offsetMin;
                rectTransform.offsetMax        = offsetMax;
                rectTransform.anchoredPosition = anchoredPosition;
            }
Ejemplo n.º 3
0
            public static void SetBottom(RectTransform rectTransform, float bottom)
            {
                Vector2 offsetMin        = rectTransform.offsetMin;
                Vector2 offsetMax        = rectTransform.offsetMax;
                Vector2 anchoredPosition = rectTransform.anchoredPosition;

                if (AnchorTool.IsStretchedVertically(rectTransform))
                {
                    offsetMin.y        = bottom;
                    anchoredPosition.y = offsetMin.y * 0.5f + offsetMax.y * 0.5f;
                }
                else
                {
                    Debug.LogWarning(rectTransform.gameObject + " is not vertically stretched");
                }

                rectTransform.offsetMin        = offsetMin;
                rectTransform.offsetMax        = offsetMax;
                rectTransform.anchoredPosition = anchoredPosition;
            }
Ejemplo n.º 4
0
            public static void SetLeft(RectTransform rectTransform, float left)
            {
                Vector2 offsetMin        = rectTransform.offsetMin;
                Vector2 offsetMax        = rectTransform.offsetMax;
                Vector2 anchoredPosition = rectTransform.anchoredPosition;

                if (AnchorTool.IsStretchedHorizontally(rectTransform))
                {
                    offsetMin.x        = left;
                    anchoredPosition.x = offsetMin.x * 0.5f + offsetMax.x * 0.5f;
                }
                else
                {
                    Debug.LogWarning(rectTransform.gameObject + " is not horizontally stretched");
                }

                rectTransform.offsetMin        = offsetMin;
                rectTransform.offsetMax        = offsetMax;
                rectTransform.anchoredPosition = anchoredPosition;
            }
            public override void ProcessFrame(Playable playable, FrameData info, object playerData)
            {
                if (_subject == null || playable.GetTime() <= 0)
                {
                    return;
                }

                float   f                = (float)(playable.GetTime() / playable.GetDuration()) * info.weight;
                Vector2 offsetMin        = _subject.offsetMin;
                Vector2 offsetMax        = _subject.offsetMax;
                Vector2 anchoredPosition = _subject.anchoredPosition;

                float curveFactor = curve.Evaluate(f);

                if (AnchorTool.IsStretchedHorizontally(_subject) && mode == Mode.Auto)
                {
                    offsetMin.x        = Mathf.Lerp(offsetMinX.src, offsetMinX.dst, curveFactor);
                    offsetMax.x        = -Mathf.Lerp(offsetMaxX.src, offsetMaxX.dst, curveFactor);
                    anchoredPosition.x = offsetMin.x * 0.5f + offsetMax.x * 0.5f;
                }
                else
                {
                    anchoredPosition.x = Mathf.Lerp(posX.src, posX.dst, curveFactor);
                }

                if (AnchorTool.IsStretchedVertically(_subject) && mode == Mode.Auto)
                {
                    offsetMin.y        = Mathf.Lerp(offsetMinY.src, offsetMinY.dst, curveFactor);
                    offsetMax.y        = -Mathf.Lerp(offsetMaxY.src, offsetMaxY.dst, curveFactor);
                    anchoredPosition.y = offsetMin.y * 0.5f + offsetMax.y * 0.5f;
                }
                else
                {
                    anchoredPosition.y = Mathf.Lerp(posY.src, posY.dst, curveFactor);
                }

                _subject.offsetMin        = offsetMin;
                _subject.offsetMax        = offsetMax;
                _subject.anchoredPosition = anchoredPosition;
            }
Ejemplo n.º 6
0
    protected override void Animate()
    {
        base.Animate();

        Vector2 offsetMin        = RectTransform.offsetMin;
        Vector2 offsetMax        = RectTransform.offsetMax;
        Vector2 anchoredPosition = RectTransform.anchoredPosition;

        float curveFactor = curve.Evaluate(factor);

        if (AnchorTool.IsStretchedHorizontally(RectTransform) && mode == Mode.Auto)
        {
            offsetMin.x        = Mathf.Lerp(offsetMinX.src, offsetMinX.dst, curveFactor);
            offsetMax.x        = -Mathf.Lerp(offsetMaxX.src, offsetMaxX.dst, curveFactor);
            anchoredPosition.x = offsetMin.x * 0.5f + offsetMax.x * 0.5f;
        }
        else
        {
            anchoredPosition.x = Mathf.Lerp(posX.src, posX.dst, curveFactor);
        }

        if (AnchorTool.IsStretchedVertically(RectTransform) && mode == Mode.Auto)
        {
            offsetMin.y        = Mathf.Lerp(offsetMinY.src, offsetMinY.dst, curveFactor);
            offsetMax.y        = -Mathf.Lerp(offsetMaxY.src, offsetMaxY.dst, curveFactor);
            anchoredPosition.y = offsetMin.y * 0.5f + offsetMax.y * 0.5f;
        }
        else
        {
            anchoredPosition.y = Mathf.Lerp(posY.src, posY.dst, curveFactor);
        }

        RectTransform.offsetMin        = offsetMin;
        RectTransform.offsetMax        = offsetMax;
        RectTransform.anchoredPosition = anchoredPosition;
    }
Ejemplo n.º 7
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        if (obj.RectTransform == null)
        {
            GUILayout.Label("Apply this script on a RectTransform", EditorStyles.boldLabel);
        }
        else
        {
            EditorGUILayout.PropertyField(resetOnStop);
            EditorGUILayout.PropertyField(duration);
            EditorGUILayout.PropertyField(curve);
            EditorGUILayout.PropertyField(behavior);
            EditorGUILayout.PropertyField(direction);

            GUILayout.Space(18);

            EditorGUILayout.PropertyField(mode);

            GUILayout.Space(9);

            if (AnchorTool.IsStretchedHorizontally(obj.RectTransform) && obj.mode == UITweenPosition.Mode.Auto)
            {
                GUILayout.Label("Horizontal Stretching Offset", EditorStyles.largeLabel);

                GUILayout.Label("Left", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(offsetMinX.FindPropertyRelative("src"));
                EditorGUILayout.PropertyField(offsetMinX.FindPropertyRelative("dst"));

                GUILayout.Space(9);

                GUILayout.Label("Right", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(offsetMaxX.FindPropertyRelative("src"));
                EditorGUILayout.PropertyField(offsetMaxX.FindPropertyRelative("dst"));

                bool copyXCurrentSRC = GUILayout.Button("Copy Stretch to src");
                bool copyXCurrentDST = GUILayout.Button("Copy Stretch to dst");

                if (copyXCurrentSRC)
                {
                    offsetMaxX.FindPropertyRelative("src").floatValue = -obj.RectTransform.offsetMax.x;
                    offsetMinX.FindPropertyRelative("src").floatValue = obj.RectTransform.offsetMin.x;
                }

                if (copyXCurrentDST)
                {
                    offsetMaxX.FindPropertyRelative("dst").floatValue = -obj.RectTransform.offsetMax.x;
                    offsetMinX.FindPropertyRelative("dst").floatValue = obj.RectTransform.offsetMin.x;
                }
            }
            else
            {
                GUILayout.Label("Horizontal Position", EditorStyles.largeLabel);

                EditorGUILayout.PropertyField(posX.FindPropertyRelative("src"));
                EditorGUILayout.PropertyField(posX.FindPropertyRelative("dst"));

                bool copyXCurrentSRC = GUILayout.Button("Copy Position to src");
                bool copyXCurrentDST = GUILayout.Button("Copy Position to dst");

                if (copyXCurrentSRC)
                {
                    posX.FindPropertyRelative("src").floatValue = obj.RectTransform.anchoredPosition.x;
                }

                if (copyXCurrentDST)
                {
                    posX.FindPropertyRelative("dst").floatValue = obj.RectTransform.anchoredPosition.x;
                }

                GUILayout.Space(18 * 3 + 9);
            }

            if (AnchorTool.IsStretchedVertically(obj.RectTransform) && obj.mode == UITweenPosition.Mode.Auto)
            {
                GUILayout.Label("Vertical Stretching Offset", EditorStyles.largeLabel);

                GUILayout.Label("Top", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(offsetMaxY.FindPropertyRelative("src"));
                EditorGUILayout.PropertyField(offsetMaxY.FindPropertyRelative("dst"));

                GUILayout.Space(9);

                GUILayout.Label("Bottom", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(offsetMinY.FindPropertyRelative("src"));
                EditorGUILayout.PropertyField(offsetMinY.FindPropertyRelative("dst"));


                bool copyYCurrentSRC = GUILayout.Button("Copy Stretch to src");
                bool copyYCurrentDST = GUILayout.Button("Copy Stretch to dst");

                if (copyYCurrentSRC)
                {
                    offsetMaxY.FindPropertyRelative("src").floatValue = -obj.RectTransform.offsetMax.y;
                    offsetMinY.FindPropertyRelative("src").floatValue = obj.RectTransform.offsetMin.y;
                }

                if (copyYCurrentDST)
                {
                    offsetMaxY.FindPropertyRelative("dst").floatValue = -obj.RectTransform.offsetMax.y;
                    offsetMinY.FindPropertyRelative("dst").floatValue = obj.RectTransform.offsetMin.y;
                }
            }
            else
            {
                GUILayout.Label("Vertical Position", EditorStyles.largeLabel);

                EditorGUILayout.PropertyField(posY.FindPropertyRelative("src"));
                EditorGUILayout.PropertyField(posY.FindPropertyRelative("dst"));

                bool copyYCurrentSRC = GUILayout.Button("Copy Position to src");
                bool copyYCurrentDST = GUILayout.Button("Copy Position to dst");

                if (copyYCurrentSRC)
                {
                    posY.FindPropertyRelative("src").floatValue = obj.RectTransform.anchoredPosition.y;
                }

                if (copyYCurrentDST)
                {
                    posY.FindPropertyRelative("dst").floatValue = obj.RectTransform.anchoredPosition.y;
                }

                GUILayout.Space(9);
            }
        }

        serializedObject.ApplyModifiedProperties();
    }