Exemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            position = EditorGUI.PrefixLabel(position, label);

            var typeProp     = property.FindPropertyRelative("type");
            int type         = typeProp.intValue;
            var strengthProp = property.FindPropertyRelative("strength");

            var image = (Texture2D)EditorGUIUtility.Load("Builtin Skins/DarkSkin/Images/pane options.png");

            var btnRect = new Rect(position.x + 1, position.y + 2, image.width, image.height);

            using (var scope = new ChangeCheckScope(null)) {
                EditorGUIUtility.AddCursorRect(btnRect, MouseCursor.Arrow);

                System.Enum newType;
                if (fieldInfo.FieldType == typeof(CustomizableInterpolator))
                {
                    newType = EditorGUI.EnumPopup(btnRect, GUIContent.none, (CustomizableInterpolator.Type)type, ButtonStyle);
                }
                else
                {
                    newType = EditorGUI.EnumPopup(btnRect, GUIContent.none, (Interpolator.Type)type, ButtonStyle);
                }

                if (scope.Changed)
                {
                    typeProp.intValue       = type = (int)(CustomizableInterpolator.Type)newType;
                    strengthProp.floatValue = .5f;
                }
            }

            if ((CustomizableInterpolator.Type)type == CustomizableInterpolator.Type.CustomCurve)
            {
                EditorGUIUtility.AddCursorRect(position, MouseCursor.Zoom);
                EditorGUI.PropertyField(position, property.FindPropertyRelative("customCurve"), GUIContent.none);
            }
            else
            {
                bool drawStrength;

                switch ((CustomizableInterpolator.Type)type)
                {
                case CustomizableInterpolator.Type.Linear:
                case CustomizableInterpolator.Type.Parabolic:
                case CustomizableInterpolator.Type.Sine:
                    drawStrength = false;
                    break;

                default:
                    strengthProp.floatValue = Mathf.Clamp01(EditorEx.DragValue(position, strengthProp.floatValue, .01f));
                    drawStrength            = true;
                    break;
                }

                if (Event.current.type == EventType.Repaint)
                {
                    Sample(type, strengthProp.floatValue, Mathf.Min((int)position.width, 256), .002f);
                    DrawCurve(position, drawStrength);
                }
            }

            var content = new GUIContent();

            content.image = image;
            EditorGUI.LabelField(btnRect, content, GUIStyle.none);
        }
Exemplo n.º 2
0
            public override void OnInspectorGUI()
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                var rect  = EditorGUILayout.GetControlRect();
                var rect1 = rect;

                // controll foldout
                using (var scope = new ChangeCheckScope(target)) {
                    rect1.width = rect1.height;
                    bool result = GUI.Toggle(rect1, target.m_FoldoutController, GUIContent.none, EditorStyles.foldout);
                    if (scope.Changed)
                    {
                        target.m_FoldoutController = result;
                    }
                }

                // controll label
                rect.xMin = rect1.xMax;
                EditorGUI.LabelField(rect, "Controller", EditorStyles.boldLabel);

                serializedObject.Update();

                // controll settings
                if (target.m_FoldoutController)
                {
                    EditorGUILayout.PropertyField(m_DurationProp);
                    EditorGUILayout.PropertyField(m_UpdateModeProp);
                    EditorGUILayout.PropertyField(m_TimeModePorp);
                    EditorGUILayout.PropertyField(m_WrapModePorp);
                    EditorGUILayout.PropertyField(m_ArrivedActionProp);

                    GUILayout.Space(4);
                }

                EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), EditorStyles.centeredGreyMiniLabel.normal.textColor);
                GUILayout.Space(4);

                rect  = EditorGUILayout.GetControlRect();
                rect1 = rect;

                // play button
                rect1.width = EditorGUIUtility.singleLineHeight * 2 - 4;

                var content = new GUIContent();

                content.text = "Play";

                using (new GUIContentColorScope(target.Playing? ProgressForegroundValid : EditorStyles.label.normal.textColor)) {
                    target.Playing = GUI.Toggle(rect1, target.Playing, content, ImageButtonSytle);
                }

                // direction button
                rect1.x = rect.xMax - rect1.width;

                content.text = target.playDirection == PlayDirection.Forward ? "->" : "<-";

                using (new DisabledScope(!target.Playing)) {
                    using (new GUIContentColorScope(EditorStyles.label.normal.textColor)) {
                        if (GUI.Button(rect1, content, ImageButtonSytle))
                        {
                            target.ReverseDirection();
                        }
                    }
                }

                rect.xMin += EditorGUIUtility.singleLineHeight * 2;
                rect.xMax -= EditorGUIUtility.singleLineHeight * 2;

                // start of dragging
                if (Event.current.type == EventType.MouseDown)
                {
                    if (rect.Contains(Event.current.mousePosition))
                    {
                        target.Dragging = true;
                    }
                }

                // end of dragging
                if (Event.current.rawType == EventType.MouseUp)
                {
                    if (target.Dragging)
                    {
                        target.Dragging = false;
                        Repaint();
                    }
                }

                // progress bar
                using (var scope = new ChangeCheckScope(null)) {
                    float progress = EditorEx.ProgressBar(rect, target.NormalizedTime, ProgressBackgroundInvalid, ProgressForegroundValid);
                    if (scope.Changed && target.Dragging)
                    {
                        target.NormalizedTime = progress;
                    }
                }

                GUILayout.Space(4);
                EditorGUILayout.EndVertical();
                GUILayout.Space(4);

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                rect  = EditorGUILayout.GetControlRect();
                rect1 = rect;

                // events foldout
                using (var scope = new ChangeCheckScope(target)) {
                    rect1.width = rect1.height;
                    bool result = GUI.Toggle(rect1, target.m_Foldoutevents, GUIContent.none, EditorStyles.foldout);
                    if (scope.Changed)
                    {
                        target.m_Foldoutevents = result;
                    }
                }

                // events label
                rect.xMin = rect1.xMax;
                EditorGUI.LabelField(rect, "Events", EditorStyles.boldLabel);

                // events
                if (target.m_Foldoutevents)
                {
                    EditorGUILayout.PropertyField(m_OnForwardArriedProp);
                    GUILayout.Space(2);
                    EditorGUILayout.PropertyField(m_OnBackwardArrivedProp);
                    GUILayout.Space(2);
                }

                serializedObject.ApplyModifiedProperties();

                EditorGUILayout.EndVertical();
                GUILayout.Space(4);
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                // draw animation list
                if (target.m_Animations != null && target.m_Animations.Count != 0)
                {
                    int editorIndex = 0;
                    for (int i = 0; i < target.m_Animations.Count; i++)
                    {
                        var anim = target.m_Animations[i];
                        if (anim)
                        {
                            if (m_Editors.Count <= editorIndex)
                            {
                                m_Editors.Add(null);
                            }

                            if (!m_Editors[editorIndex] || m_Editors[editorIndex].target != anim)
                            {
                                if (!Application.isPlaying)
                                {
                                    Object.DestroyImmediate(m_Editors[editorIndex]);
                                }
                                else
                                {
                                    Object.Destroy(m_Editors[editorIndex]);
                                }

                                m_Editors[editorIndex] = CreateEditor(anim);
                            }

                            (m_Editors[editorIndex] as TweenAnimation.Editor).OnInsPectorGUI(target);
                            editorIndex++;
                        }
                        else
                        {
                            target.m_Animations.RemoveAt(i--);
                        }
                    }

                    for (; editorIndex < m_Editors.Count; editorIndex++)
                    {
                        if (!Application.isPlaying)
                        {
                            Object.DestroyImmediate(m_Editors[editorIndex]);
                        }
                        else
                        {
                            Object.Destroy(m_Editors[editorIndex]);
                        }

                        m_Editors.RemoveAt(editorIndex--);
                    }
                }

                // add button
                GUILayout.Space(4);
                var btnRect = EditorGUILayout.GetControlRect();

                if (GUI.Button(btnRect, "Add Animation..", EditorStyles.miniButton))
                {
                    ShowAddMenu(btnRect);
                }
                GUILayout.Space(4);

                EditorGUILayout.EndVertical();
            }