Exemple #1
0
        public void Update()
        {
            Instance = this;

            InternalUiAnimationEditorSelection.Update();

            if (InternalUiAnimationEditorSelection.TargetGameObject == null)
            {
                return;
            }

            if (InternalUiAnimationEditorSelection.TargetAnimation == null)
            {
                return;
            }

            InternalUiAnimationEditorPlayer.Update();
            InternalUiAnimationEditorTimeline.Update();
            InternalUiAnimationEditorCanvas.Update();

            Repaint();
        }
Exemple #2
0
        public static void Update()
        {
            if (DragAndDropQueue != null)
            {
                for (int i = 0; i < DragAndDropQueue.Count; i++)
                {
                    UiAnimationClipSegment tween = new UiAnimationClipSegment();
                    tween.GameObject = DragAndDropQueue[i] as GameObject;
                    tween.Delay      = GetTimeByMousePosition(InternalUiAnimationEditor.MousePosition.x);
                    tween.Layer      = GetLayerByMousePosition(InternalUiAnimationEditor.MousePosition.y);

                    RectTransform rectTransform = tween.GameObject.GetComponent <RectTransform>();

                    if (rectTransform != null)
                    {
                        tween.PositionFrom = new Vector2(rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);
                        tween.PositionTo   = new Vector2(rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);

                        tween.RotationFrom = rectTransform.localRotation.eulerAngles.z;
                        tween.RotationTo   = rectTransform.localRotation.eulerAngles.z;

                        tween.ScaleFrom = new Vector2(rectTransform.localScale.x, rectTransform.localScale.y);
                        tween.ScaleTo   = new Vector2(rectTransform.localScale.x, rectTransform.localScale.y);
                    }

                    if (InternalUiAnimationEditorSelection.TargetAnimationClip != null)
                    {
                        InternalUiAnimationEditorSelection.TargetAnimationClip.Items.Add(tween);
                        InternalUiAnimationEditorSelection.TargetAnimationClip.Items.Sort((a, b) => (a.Delay.CompareTo(b.Delay)));

                        justAddedTween = tween;
                    }
                }

                DragAndDropQueue = null;
            }

            if (InternalUiAnimationEditorSelection.CanvasItemToEdit == null)
            {
                Items = new List <InternalUiAnimationEditorCanvasItem>();

                for (int i = 0; i < InternalUiAnimationEditorSelection.TargetAnimationClip.Items.Count; i++)
                {
                    InternalUiAnimationEditorCanvasItem canvasItem = new InternalUiAnimationEditorCanvasItem
                                                                     (
                        InternalUiAnimationEditorSelection.TargetAnimationClip.Items[i]
                                                                     );

                    Items.Add(canvasItem);

                    if (canvasItem.Target == justAddedTween)
                    {
                        InternalUiAnimationEditorSelection.SetCanvasItemToEdit(canvasItem);
                        justAddedTween = null;
                    }
                }
            }

            if (InternalUiAnimationEditorSelection.CanvasItemToEdit != null)
            {
                Items.Remove(InternalUiAnimationEditorSelection.CanvasItemToEdit);
                Items.Add(InternalUiAnimationEditorSelection.CanvasItemToEdit);
            }

            if (InternalUiAnimationEditorSelection.CanvasItemToDrag != null)
            {
                UpdateDrag(InternalUiAnimationEditorSelection.CanvasItemToDrag);
            }

            if (InternalUiAnimationEditorSelection.CanvasItemToResize != null)
            {
                UpdateResize(InternalUiAnimationEditorSelection.CanvasItemToResize);
            }

            for (int i = 0; i < Items.Count; i++)
            {
                Items[i].IsCollided = false;

                for (int j = 0; j < Items.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    if (Items[i].Target.GameObject != Items[j].Target.GameObject)
                    {
                        continue;
                    }

                    if (Items[i].Target.ItemType != Items[j].Target.ItemType)
                    {
                        continue;
                    }

                    if (Items[i].HitTest(Items[j].X, Items[i].Y) || Items[j].HitTest(Items[i].X, Items[j].Y))
                    {
                        Items[i].IsCollided = true;
                        break;
                    }
                }
            }
        }
Exemple #3
0
        public static void OnEvent()
        {
            if (Event.current.type == EventType.DragUpdated)
            {
                if (InternalUiAnimationEditor.MousePosition.x > InternalUiAnimationEditorInspector.Width)
                {
                    InternalUiAnimationEditorSelection.SetCanvasItemToEdit(null);
                }
            }

            // Drag and drop game objects
            if (Event.current.type == EventType.DragExited)
            {
                if (InternalUiAnimationEditor.MousePosition.x > InternalUiAnimationEditorInspector.Width && InternalUiAnimationEditor.MousePosition.y > InternalUiAnimationEditorTimeline.Height)
                {
                    object[] objects = DragAndDrop.objectReferences;
                    DragAndDropQueue = new List <GameObject>();

                    for (int i = 0; i < objects.Length; i++)
                    {
                        if (objects[i] is GameObject)
                        {
                            DragAndDropQueue.Add(objects[i] as GameObject);
                        }
                    }

                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.MouseDown)
            {
                InternalUiAnimationEditorCanvasItem item = GetItemAt(InternalUiAnimationEditor.MousePosition.x, InternalUiAnimationEditor.MousePosition.y);

                if (item != null)
                {
                    if (InternalUiAnimationEditor.MousePosition.x > item.X + item.Width - 10 && InternalUiAnimationEditor.MousePosition.x < item.X + item.Width)
                    {
                        InternalUiAnimationEditorSelection.SetCanvasItemToEdit(item);
                        InternalUiAnimationEditorSelection.SetCanvasItemToResize(item);
                    }

                    else
                    {
                        InternalUiAnimationEditorSelection.SetCanvasItemToEdit(item);
                        InternalUiAnimationEditorSelection.SetCanvasItemToDrag(item);

                        item.CachedX = item.X;
                        item.CachedY = item.Y;
                    }
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                InternalUiAnimationEditorSelection.SetCanvasItemToDrag(null);
                InternalUiAnimationEditorSelection.SetCanvasItemToResize(null);

                if (InternalUiAnimationEditor.MousePosition.x > InternalUiAnimationEditorInspector.Width)
                {
                    InternalUiAnimationEditorCanvasItem item = GetItemAt(InternalUiAnimationEditor.MousePosition.x, InternalUiAnimationEditor.MousePosition.y);

                    if (item != null)
                    {
                        if (InternalUiAnimationEditorSelection.CanvasItemToEdit == null)
                        {
                            InternalUiAnimationEditorSelection.SetCanvasItemToEdit(item);
                        }
                    }
                    else
                    {
                        InternalUiAnimationEditorSelection.SetCanvasItemToEdit(null);
                    }
                }
            }
        }
        private static void RenderMenu(float positionX, float positionY, float width, float height)
        {
            GUIStyle splitStyle = new GUIStyle();

            splitStyle.fixedWidth        = 1;
            splitStyle.fixedHeight       = height;
            splitStyle.margin            = new RectOffset(0, 0, 0, 0);
            splitStyle.normal.background = InternalUiAnimationEditorTextures.ColorBlack20;

            GUIStyle dropdownStyle = new GUIStyle(new GUIStyle(GUI.skin.GetStyle("Popup")));

            dropdownStyle.fixedHeight        = height;
            dropdownStyle.margin             = new RectOffset(0, 0, 0, 0);
            dropdownStyle.normal.background  = InternalUiAnimationEditorTextures.ColorInvisible;
            dropdownStyle.hover.background   = InternalUiAnimationEditorTextures.ColorBlack10;
            dropdownStyle.active.background  = InternalUiAnimationEditorTextures.ColorBlack20;
            dropdownStyle.focused.background = InternalUiAnimationEditorTextures.ColorInvisible;

            GUIStyle buttonStyle = new GUIStyle(new GUIStyle(GUI.skin.GetStyle("Button")));

            buttonStyle.fixedWidth        = height;
            buttonStyle.fixedHeight       = height;
            buttonStyle.normal.background = InternalUiAnimationEditorTextures.ColorInvisible;
            buttonStyle.hover.background  = InternalUiAnimationEditorTextures.ColorBlack10;
            buttonStyle.active.background = InternalUiAnimationEditorTextures.ColorBlack20;
            buttonStyle.margin            = new RectOffset(0, 0, 0, 0);
            buttonStyle.padding           = new RectOffset(0, 0, 0, 0);

            GUILayout.BeginArea(new Rect(positionX, positionY, width - 0, height), new GUIStyle());
            GUILayout.BeginHorizontal();

            // Play button
            if (InternalUiAnimationEditorPlayer.Activated)
            {
                Texture2D icon  = new Texture2D(8, 8);
                Color     color = new Color(0.22f, 0.22f, 0.22f, 1);
                for (int x = 0; x < icon.width; x++)
                {
                    for (int y = 0; y < icon.height; y++)
                    {
                        icon.SetPixel(x, y, color);
                    }
                }
                icon.Apply();

                InternalUiAnimationEditorGUI.Button
                (
                    icon,
                    buttonStyle,
                    () =>
                {
                    InternalUiAnimationEditorPlayer.Stop();
                }
                );
                GUILayout.Box(string.Empty, splitStyle);
            }
            else
            {
                InternalUiAnimationEditorGUI.Button
                (
                    EditorGUIUtility.IconContent("Animation.Play").image,
                    buttonStyle,
                    () =>
                {
                    InternalUiAnimationEditorPlayer.Play();
                }
                );
                GUILayout.Box(string.Empty, splitStyle);
            }

            // Active timeline popup
            InternalUiAnimationEditorGUI.Popup
            (
                InternalUiAnimationEditorSelection.TargetAnimationClipIndex,
                InternalUiAnimationEditorSelection.GetAnimationClipsNames(),
                dropdownStyle,
                (int value) =>
            {
                GUI.FocusControl(string.Empty);
                InternalUiAnimationEditorSelection.SetTargetAnimationClipIndex(value);
            }
            );

            GUILayout.Box(string.Empty, splitStyle);

            // Add timeline button
            InternalUiAnimationEditorGUI.Button
            (
                EditorGUIUtility.IconContent("Toolbar Plus").image,
                buttonStyle,
                () =>
            {
                if (InternalUiAnimationEditorSelection.TargetAnimation != null)
                {
                    UiAnimationClip timeline = new UiAnimationClip();
                    timeline.Name            = "New Timeline " + InternalUiAnimationEditorSelection.TargetAnimation.AnimationClips.Count;

                    InternalUiAnimationEditorSelection.TargetAnimation.AnimationClips.Add(timeline);
                    InternalUiAnimationEditorSelection.SetTargetAnimationClipIndex(InternalUiAnimationEditorSelection.TargetAnimation.AnimationClips.IndexOf(timeline));
                }
            }
            );
            GUILayout.Box(string.Empty, splitStyle);

            // Remove timeline button
            InternalUiAnimationEditorGUI.Button
            (
                EditorGUIUtility.IconContent("Toolbar Minus").image,
                buttonStyle,
                () =>
            {
                if (InternalUiAnimationEditorSelection.TargetAnimation != null)
                {
                    if (InternalUiAnimationEditorSelection.TargetAnimation.AnimationClips.Count > 1)
                    {
                        if (EditorUtility.DisplayDialog("Error", "Are you sure you want to delete " + InternalUiAnimationEditorSelection.TargetAnimationClip.Name + "?", "Yes", "No"))
                        {
                            InternalUiAnimationEditorSelection.TargetAnimation.AnimationClips.RemoveAt(InternalUiAnimationEditorSelection.TargetAnimationClipIndex);
                            InternalUiAnimationEditorSelection.SetTargetAnimationClipIndex(0);
                        }
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Error", "You can not delete last timeline.", "OK");
                    }
                }
            }
            );
            GUILayout.Box(string.Empty, splitStyle);

            // Dropdown icon
            Texture dropdownIcon = EditorGUIUtility.IconContent("Icon Dropdown").image;

            InternalUiAnimationEditorGUI.DrawTexture(width - 60, positionY + 9, dropdownIcon.width, dropdownIcon.height, dropdownIcon);

            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
        private static void RenderAnimationClipSegment(UiAnimationClipSegment segment)
        {
            if (segment.GameObject == null)
            {
                EditorGUILayout.HelpBox("Game object is missed! Setup another game object or delete this segment.", MessageType.Error);
            }

            segment.GameObject = InternalUiAnimationEditorGUI.InspectorObjectField
                                 (
                "Game Object",
                segment.GameObject
                                 );

            if (segment.GameObject != null)
            {
                segment.ItemType = (UiAnimationClipSegmentType)InternalUiAnimationEditorGUI.InspectorEnumPopup
                                   (
                    "Type",
                    segment.ItemType,
                    () =>
                {
                    RectTransform rectTransform = segment.GameObject.GetComponent <RectTransform>();

                    if (rectTransform != null)
                    {
                        segment.PositionFrom = new Vector2(rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);
                        segment.PositionTo   = new Vector2(rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);

                        segment.RotationFrom = rectTransform.localRotation.eulerAngles.z;
                        segment.RotationTo   = rectTransform.localRotation.eulerAngles.z;

                        segment.ScaleFrom = new Vector2(rectTransform.localScale.x, rectTransform.localScale.y);
                        segment.ScaleTo   = new Vector2(rectTransform.localScale.x, rectTransform.localScale.y);
                    }
                }
                                   );

                segment.EasingType = (EasingType)InternalUiAnimationEditorGUI.InspectorEnumPopup
                                     (
                    "Easing type",
                    segment.EasingType
                                     );

                switch (segment.ItemType)
                {
                case UiAnimationClipSegmentType.Alpha:
                    segment.AlphaFrom = InternalUiAnimationEditorGUI.InspectorFloatField("Alpha From", segment.AlphaFrom);
                    segment.AlphaTo   = InternalUiAnimationEditorGUI.InspectorFloatField("Alpha To", segment.AlphaTo);
                    break;

                case UiAnimationClipSegmentType.Color:
                    segment.ColorFrom = InternalUiAnimationEditorGUI.InspectorColorField("Color From", segment.ColorFrom);
                    segment.ColorTo   = InternalUiAnimationEditorGUI.InspectorColorField("Color To", segment.ColorTo);
                    break;

                case UiAnimationClipSegmentType.Position:
                    segment.PositionFrom = InternalUiAnimationEditorGUI.InspectorVector2Field("Position From XY", segment.PositionFrom);
                    segment.PositionTo   = InternalUiAnimationEditorGUI.InspectorVector2Field("Position To XY", segment.PositionTo);
                    break;

                case UiAnimationClipSegmentType.Rotation:
                    segment.RotationFrom = InternalUiAnimationEditorGUI.InspectorFloatField("Rotation From", segment.RotationFrom);
                    segment.RotationTo   = InternalUiAnimationEditorGUI.InspectorFloatField("Rotation To", segment.RotationTo);
                    break;

                case UiAnimationClipSegmentType.Scale:
                    segment.ScaleFrom = InternalUiAnimationEditorGUI.InspectorVector2Field("Scale From XY", segment.ScaleFrom);
                    segment.ScaleTo   = InternalUiAnimationEditorGUI.InspectorVector2Field("Scale To XY", segment.ScaleTo);
                    break;
                }

                segment.Predefined = InternalUiAnimationEditorGUI.InspectorBooleanField
                                     (
                    new GUIContent("Predefined", "Use From value as predefined value for " + segment.GameObject.name),
                    segment.Predefined
                                     );

                /*
                 * UtilityReflection.SetMemberValue
                 * (
                 *  segment, "Predefined",
                 *  segment.Predefined = InternalUiAnimationEditorGUI.InspectorBooleanField
                 *  (
                 *      new GUIContent("Predefined", "Use From value as predefined value for " + segment.GameObject.name),
                 *      (bool)UtilityReflection.GetMemberValue(segment, "Predefined")
                 *  )
                 * );
                 */
            }

            GUIStyle buttonStyle = new GUIStyle(GUI.skin.GetStyle("Button"));

            buttonStyle.margin.left = 138;
            buttonStyle.margin.top  = 5;

            EditorGUI.BeginChangeCheck();
            GUILayout.Button("Delete segment", buttonStyle);
            if (EditorGUI.EndChangeCheck())
            {
                InternalUiAnimationEditorSelection.TargetAnimationClip.Items.Remove(segment);
                InternalUiAnimationEditorSelection.TargetAnimationClip.Items.Sort((a, b) => (a.Delay.CompareTo(b.Delay)));
                InternalUiAnimationEditorSelection.SetCanvasItemToEdit(null);
            }
        }