Example #1
0
        public static void OnAddButton(State state)
        {
            var tweenMenu = new GenericMenu();

            foreach (var editor in Editors)
            {
                if (!editor.IsMultiple && state.Items.Any(t => t.GetType() == editor.Type))
                {
                    tweenMenu.AddDisabledItem(new GUIContent(editor.Name));
                    continue;
                }

                tweenMenu.AddItem(new GUIContent(editor.Name), false, () =>
                                  EditorActions.Add(() =>
                {
                    editor.AddAction(state);

                    //TODO move it to EditorState class
                    EditorState.Get(state).OnTweenAdded(state.Last);
                },
                                                    InspectorStates.States, "Add tween"));
            }

            tweenMenu.ShowAsContext();
        }
Example #2
0
        private void OnDisable()
        {
            Undo.undoRedoPerformed -= PrecessUndo;

            EditorActions.Clear();
            EditorState.Clear();
            EditorState.Repaint = null;
            States = null;
        }
Example #3
0
 private void OnRemoveButton()
 {
     EditorActions.Add(() =>
     {
         Editors.Remove(_state.Id);
         _state.Group.RemoveState(_state);
         Reorder(_state.Group);
     },
                       InspectorStates.States, "Remove state");
 }
Example #4
0
        public static void OnRemoveButton(State state, int index)
        {
            EditorActions.Add(() =>
            {
                //TODO move it to EditorState class
                EditorState.Get(state).OnTweenRemoving(state[index]);

                state.RemoveTween(state[index]);
            },
                              InspectorStates.States, "Remove tween");
        }
Example #5
0
        private static void OnAddStateButton(Group group)
        {
            EditorActions.Add(() =>
            {
                var state = group.CreateState();

                EditorState.Reorder(group);
                EditorState.Get(state).Open();
            },
                              InspectorStates.States, "Add State");
        }
Example #6
0
        private void OnEnable()
        {
            Undo.undoRedoPerformed += PrecessUndo;

            EditorActions.Clear();
            EditorState.Clear();
            EditorState.Repaint = Repaint;

            States = (States)target;

            SerializedState = serializedObject;

            EditorGroup.Enable(States.Group);
        }
Example #7
0
        public override void OnInspectorGUI()
        {
            SerializedState.Update();

            GUILayout.BeginHorizontal();
            GUILayout.Space(-8);

            GUILayout.BeginVertical();
            GUILayout.Space(2);

            EditorGroup.Draw(States.Group);

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            EditorActions.Process();

            SerializedState.ApplyModifiedProperties();
        }
Example #8
0
        public void DrawHeader(Rect rect, T tween)
        {
            EditorLayout.SetSize(new Vector2(rect.width, rect.height));
            EditorLayout.SetPosition(rect.x, rect.y);

            EditorGUI.BeginDisabledGroup(!tween.Component);

            EditorLayout.Control(18, r =>
            {
                var tweenEnabled = EditorGUI.ToggleLeft(r, GUIContent.none, tween.Enabled, EditorStyles.label);
                if (tweenEnabled != tween.Enabled)
                {
                    EditorActions.Add(() => tween.Enabled = tweenEnabled, InspectorStates.States);
                }
            });

            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(!tween.Enabled);

            EditorLayout.Control(rect.width - EditorConfig.Sizes.Offset * 5 - 150, r =>
            {
                EditorGUI.LabelField(r, DisplayName, EditorStyles.label);
            });

            EditorLayout.Control(100, r =>
            {
                if (tween.EaseFunc != null)
                {
                    EditorEase.Draw(r, tween);
                }
                else
                {
                    EditorGUI.HelpBox(r, tween.EaseName, MessageType.Warning);
                }
            });

            EditorLayout.Control(18, r =>
            {
                if (GUI.Button(r, EditorConfig.Content.IconRecord, EditorConfig.Styles.IconButton))
                {
                    EditorActions.Add(() => Capture(tween), InspectorStates.States);
                }
            });

            EditorLayout.Control(18, r =>
            {
                if (GUI.Button(r, EditorConfig.Content.IconReturn, EditorConfig.Styles.IconButton))
                {
                    EditorActions.Add(tween.Apply, tween.Component);
                }
            });

            EditorLayout.Space(0);

            var rangeMin = tween.Range.x;
            var rangeMax = tween.Range.y;

            EditorLayout.Control(rect.width, r =>
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.MinMaxSlider(r, ref rangeMin, ref rangeMax, 0, 1);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorActions.Add(() => tween.Range = new Vector2(rangeMin, rangeMax), InspectorStates.States, "tween range");
                }
            });

            EditorGUI.EndDisabledGroup();

            if (!tween.Component)
            {
                var rectWarning = new Rect(rect.x, rect.y - EditorConfig.Sizes.Offset, rect.width + EditorConfig.Sizes.Offset * 2, TotalHeight - EditorConfig.Sizes.Offset);
                EditorGUI.DrawRect(rectWarning, EditorConfig.Colors.EditorBackGrey);
                EditorGUI.HelpBox(rectWarning, $"Tween {DisplayName} require {typeof(C)} component!", MessageType.Warning);

                var rectButton = new Rect(rect.width, rect.y + rect.height - 30, 50, 20);

                return;
            }

            if (DrawValueFunc == null)
            {
                return;
            }

            EditorGUI.BeginDisabledGroup(!tween.Enabled);

            EditorLayout.Space(0);
            EditorLayout.SetWidth(rect.width);
            EditorLayout.PropertyField(ref tween.Value, DrawValueFunc, InspectorStates.Record, _content);

            EditorGUI.EndDisabledGroup();
        }
Example #9
0
        private static void DrawHeader(Rect rect, EditorState editor)
        {
            var rectBackground = new Rect(rect.x, rect.y, rect.width, rect.height - 6);

            EditorGUI.DrawRect(rectBackground, EditorConfig.Colors.LightGrey);

            var rectFoldOutBack = new Rect(rect.x, rect.y, rect.width, EditorConfig.Sizes.LineHeight);

            GUI.Box(rectFoldOutBack, GUIContent.none, GUI.skin.box);

            var rectStateTabColor = new Rect(rect.x, rect.y, 2, EditorConfig.Sizes.LineHeight);
            var tabColor          = Color.gray;

            if (editor._state.IsOpenedState)
            {
                tabColor = EditorConfig.Colors.Green;
            }
            if (editor._state.IsClosedState)
            {
                tabColor = EditorConfig.Colors.Red;
            }
            EditorGUI.DrawRect(rectStateTabColor, tabColor);

            var rectToggle = new Rect(rect.x + 5, rect.y + 2, 20, EditorConfig.Sizes.SingleLine);

            if (editor._state.IsDefaultState)
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUI.Toggle(rectToggle, GUIContent.none, true);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                editor._state.Enabled = EditorLayout.PropertyField(rectToggle, editor._state.Enabled, EditorGUI.Toggle, InspectorStates.Record);
            }

            var rectFoldout = new Rect(rect.x + 34, rect.y + 2, rect.width - 116, EditorConfig.Sizes.SingleLine);

            editor._foldout.target = EditorGUI.Foldout(rectFoldout, editor._foldout.target, new GUIContent(editor._state.Name), true, EditorConfig.Styles.Foldout);

            var rectButton = new Rect(rect.width, rect.y + 3, 24, EditorConfig.Sizes.SingleLine);

            EditorGUI.BeginDisabledGroup(editor._state.IsDefaultState);
            if (GUI.Button(rectButton, EditorConfig.Content.IconToolbarMinus, EditorConfig.Styles.PreButton))
            {
                editor.OnRemoveButton();
            }
            EditorGUI.EndDisabledGroup();



            rectButton.x -= 24;
            if (GUI.Button(rectButton, EditorConfig.Content.IconReturn, EditorConfig.Styles.IconButton))
            {
                editor._state.Apply();
            }

            rectButton.x -= 24;
            if (GUI.Button(rectButton, EditorConfig.Content.IconRecord, EditorConfig.Styles.IconButton))
            {
                EditorActions.Add(editor._state.Capture, InspectorStates.States, "Record state values");
            }
        }
Example #10
0
 public static void Record() => EditorActions.Record(States);