Exemple #1
0
        ///Display an AnimatedParameter GUI
        public static void ShowParameter(AnimatedParameter animParam, IKeyable keyable, SerializedProperty serializedProperty = null)
        {
            //Calling this through a PropertyDrawer (thus serialized property != null), seems to have some mambo jumbo spacing.
            //This fixes that spacing so that both field and property parameter editors looks the same.
            GUILayout.Space(serializedProperty != null ? 0 : 2);

            if (!animParam.isValid)
            {
                GUILayout.Label("Animatable Parameter is invalid");
                return;
            }

            var e                = Event.current;
            var keyableLength    = keyable.GetLength();
            var keyableTime      = keyable.RootTimeToLocalTime();
            var isRecording      = keyable.IsRootTimeWithinClip();
            var foldOut          = EditorTools.GetObjectFoldOut(animParam);
            var hasAnyKey        = animParam.HasAnyKey();
            var hasKeyNow        = animParam.HasKey(keyableTime);
            var hasChanged       = animParam.HasChanged();
            var parameterEnabled = animParam.enabled;
            var lastRect         = new Rect();

            GUI.backgroundColor = new Color(0, 0.4f, 0.4f, 0.5f);
            GUILayout.BeginVertical(Slate.Styles.headerBoxStyle);
            GUI.backgroundColor = Color.white;

            GUILayout.BeginHorizontal();

            var sFold = foldOut ? "▼" : "▶";
            var sName = animParam.ToString();

            GUILayout.Label(sFold, GUILayout.Width(13));
            lastRect    = GUILayoutUtility.GetLastRect();
            GUI.enabled = !animParam.isExternal || isRecording;

            GUI.backgroundColor = hasAnyKey && parameterEnabled ? new Color(1, 0.6f, 0.6f) : Color.white;
            GUI.backgroundColor = hasAnyKey && parameterEnabled && isRecording ? Slate.Styles.recordingColor : GUI.backgroundColor;

            DoParameterField(string.Format("<b>{0}</b>", sName), animParam, keyableTime);

            GUI.enabled         = true;
            GUI.backgroundColor = Color.white;

            EditorGUIUtility.AddCursorRect(lastRect, MouseCursor.Link);
            if (e.type == EventType.MouseDown && e.button == 0 && lastRect.Contains(e.mousePosition))
            {
                EditorTools.SetObjectFoldOut(animParam, !foldOut);
                e.Use();
            }

            GUI.enabled = hasAnyKey && parameterEnabled;
            if (GUILayout.Button(Slate.Styles.previousKeyIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                keyable.root.currentTime = animParam.GetKeyPrevious(keyableTime) + keyable.startTime;
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

            GUI.enabled = parameterEnabled;
            GUI.color   = hasKeyNow && parameterEnabled ? new Color(1, 0.3f, 0.3f) : Color.white;
            GUI.color   = hasAnyKey && hasChanged ? Color.green : GUI.color;
            if (GUILayout.Button(Slate.Styles.keyIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                if (e.alt)     //temporary solution
                {
                    animParam.scriptExpression = "value";
                    EditorTools.SetObjectFoldOut(animParam, true);
                }
                else
                {
                    if (!hasKeyNow || hasChanged)
                    {
                        animParam.SetKeyCurrent(keyableTime);
                    }
                    else
                    {
                        animParam.RemoveKey(keyableTime);
                    }
                }
            }
            GUI.color = Color.white;
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);


            GUI.enabled = hasAnyKey && parameterEnabled;
            if (GUILayout.Button(Slate.Styles.nextKeyIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                keyable.root.currentTime = animParam.GetKeyNext(keyableTime) + keyable.startTime;
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

            GUILayout.Space(2);

            GUI.enabled = true;
            GUI.color   = Color.white.WithAlpha(animParam.enabled ? 1 : 0.5f);
            if (GUILayout.Button(Slate.Styles.gearIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                DoParamGearContextMenu(animParam, keyable);
            }
            GUI.color = Color.white;
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

            GUI.enabled = true;
            GUILayout.EndHorizontal();

            //...
            GUILayout.Space(3);
            GUILayout.EndVertical();

            // var fade = EditorTools.GetObjectFoldOutFaded(animParam);
            if (EditorTools.GetObjectFoldOut(animParam))
            {
                var hasExpression = animParam.hasActiveExpression;

                GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.3f);
                GUILayout.BeginVertical(Slate.Styles.clipBoxFooterStyle);
                GUI.color = Color.white;

#if SLATE_USE_EXPRESSIONS
                GUILayout.BeginHorizontal();
                if (hasExpression)
                {
                    if (GUILayout.Button(Styles.expressionIcon, GUI.skin.label, GUILayout.Width(18)))
                    {
                        var menu = Slate.Expressions.ExpressionsMenuGenerator.GetExpressionEnvironmentMenu(animParam.GetExpressionEnvironment(), (template) => { animParam.scriptExpression = template; });
                        menu.ShowAsContext();
                    }
                    EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                    animParam.scriptExpression = EditorGUILayout.DelayedTextField(animParam.scriptExpression);
                }
                GUILayout.EndHorizontal();

                if (hasExpression && animParam.compileException != null)
                {
                    EditorGUILayout.HelpBox(animParam.compileException.Message, MessageType.Error);
                }
#endif

                string info = null;
                if (!parameterEnabled)
                {
                    info = "Parameter is disabled or overriden.";
                }

                if (info == null && !hasAnyKey && !hasExpression)
                {
                    info = "Parameter is not yet animated. You can make it so by creating the first key.";
                }

                if (info == null && keyableLength == 0 && hasAnyKey)
                {
                    info = "Length of Clip is zero. Can not display Curve Editor.";
                }

                if (info == null && animParam.isExternal && !isRecording)
                {
                    info = "This Parameter can only be edited when time is within the clip range.";
                }

                if (info != null)
                {
                    GUILayout.Label(info);
                }
                else
                {
                    DoCurveBox(animParam, keyable, isRecording);
                }

                GUILayout.EndVertical();
                GUILayout.Space(5);
            }
            else
            {
#if SLATE_USE_EXPRESSIONS
                if (animParam.hasActiveExpression)
                {
                    GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.3f);
                    GUILayout.BeginHorizontal(Styles.clipBoxFooterStyle);
                    GUI.color = Color.white;
                    GUILayout.Space(10);
                    GUILayout.Label(string.Format("<b>= </b><size=9>{0}</size>", animParam.scriptExpression));
                    GUILayout.EndHorizontal();
                }
#endif
            }

            // EditorGUILayout.EndFadeGroup();
        }
Exemple #2
0
        public static void ShowParameter(AnimatedParameter animParam, IKeyable keyable, SerializedProperty serializedProperty = null)
        {
            if (!animParam.isValid)
            {
                GUILayout.Label("Animatable Parameter is invalid");
                return;
            }

            var e                = Event.current;
            var keyableLength    = keyable.endTime - keyable.startTime;
            var rootTime         = keyable.root.currentTime;
            var localTime        = Mathf.Clamp(rootTime - keyable.startTime, 0, keyableLength);
            var isRecording      = rootTime >= keyable.startTime && rootTime <= keyable.endTime && rootTime > 0;
            var foldOut          = EditorTools.GetObjectFoldOut(animParam);
            var hasAnyKey        = animParam.HasAnyKey();
            var hasKeyNow        = animParam.HasKey(localTime);
            var hasChanged       = animParam.HasChanged();
            var parameterEnabled = animParam.enabled;
            var lastRect         = new Rect();

            GUI.backgroundColor = new Color(0, 0.4f, 0.4f, 0.5f);
            GUILayout.BeginVertical(Slate.Styles.headerBoxStyle);
            GUI.backgroundColor = Color.white;

            GUILayout.BeginHorizontal();


            var sFold = foldOut? "▼" : "▶";
            var sName = animParam.ToString();


            GUI.backgroundColor = hasAnyKey && parameterEnabled? new Color(1, 0.6f, 0.6f) : Color.white;
            GUI.backgroundColor = hasAnyKey && parameterEnabled && isRecording? Slate.Styles.recordingColor : GUI.backgroundColor;
            GUILayout.Label(sFold, GUILayout.Width(13));
            lastRect    = GUILayoutUtility.GetLastRect();
            GUI.enabled = !animParam.isExternal || isRecording;

            DoParameterField(string.Format("<b>{0}</b>", sName), animParam, localTime);

            GUI.enabled         = true;
            GUI.backgroundColor = Color.white;


            EditorGUIUtility.AddCursorRect(lastRect, MouseCursor.Link);
            if (e.type == EventType.MouseDown && e.button == 0 && lastRect.Contains(e.mousePosition))
            {
                EditorTools.SetObjectFoldOut(animParam, !foldOut);
                e.Use();
            }



            GUI.enabled = hasAnyKey && parameterEnabled;
            if (GUILayout.Button(Slate.Styles.previousKeyIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                keyable.root.currentTime = animParam.GetKeyPrevious(localTime) + keyable.startTime;
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);


            GUI.enabled = parameterEnabled;
            GUI.color   = hasKeyNow && parameterEnabled? new Color(1, 0.3f, 0.3f) : Color.white;
            GUI.color   = hasAnyKey && hasChanged? Color.green : GUI.color;
            if (GUILayout.Button(Slate.Styles.keyIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                if (e.alt)                  //temporary solution
                {
                    animParam.scriptExpression = "value";
                    EditorTools.SetObjectFoldOut(animParam, true);
                }
                else
                {
                    if (!hasKeyNow || hasChanged)
                    {
                        animParam.SetKeyCurrent(localTime);
                    }
                    else
                    {
                        animParam.RemoveKey(localTime);
                    }
                }
            }
            GUI.color = Color.white;
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);


            GUI.enabled = hasAnyKey && parameterEnabled;
            if (GUILayout.Button(Slate.Styles.nextKeyIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                keyable.root.currentTime = animParam.GetKeyNext(localTime) + keyable.startTime;
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

            GUILayout.Space(2);

            // GUI.enabled = (hasAnyKey && parameterEnabled) || animParam.isExternal;
            GUI.enabled = parameterEnabled;
            if (GUILayout.Button(Slate.Styles.gearIcon, GUIStyle.none, GUILayout.Height(20), GUILayout.Width(16)))
            {
                DoParamGearContextMenu(animParam, keyable);
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);

            GUI.enabled = true;
            GUILayout.EndHorizontal();

            //...
            GUILayout.EndVertical();

            if (EditorGUILayout.BeginFadeGroup(EditorTools.GetObjectFoldOutFaded(animParam)))
            {
                GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.3f);
                GUILayout.BeginVertical(Slate.Styles.clipBoxFooterStyle);
                GUI.color = Color.white;

#if SLATE_USE_EXPRESSIONS
                GUILayout.BeginHorizontal();
                var exp = animParam.scriptExpression;
                if (!string.IsNullOrEmpty(exp))
                {
                    exp = EditorGUILayout.TextArea(exp);
                    animParam.scriptExpression = exp;
                }
                if (GUILayout.Button("f", GUILayout.Width(20)))
                {
                    var menu = GetExpressionEnvirontmentMenu(animParam.GetExpressionEnvironment(), (template) => { animParam.scriptExpression = template; });
                    menu.ShowAsContext();
                }
                GUILayout.EndHorizontal();

                if (animParam.compileException != null)
                {
                    EditorGUILayout.HelpBox(animParam.compileException.Message, MessageType.Error);
                }
#endif

                string info = null;
                if (!parameterEnabled)
                {
                    info = "Parameter is disabled or overriden.";
                }

                if (info == null && !hasAnyKey)
                {
                    info = "Parameter is not yet animated. You can make it so by creating the first key.";
                }

                if (info == null && keyableLength == 0 && hasAnyKey)
                {
                    info = "Length of Clip is zero. Can not display Curve Editor.";
                }

                if (info == null && animParam.isExternal && !isRecording)
                {
                    info = "This Parameter can only be edited when time is within the clip range.";
                }

                if (info != null)
                {
                    GUILayout.Label(info);
                }
                else
                {
                    DoCurveBox(animParam, keyable, isRecording);
                }

                GUILayout.EndVertical();
                GUILayout.Space(5);
            }
            else
            {
#if SLATE_USE_EXPRESSIONS
                if (!string.IsNullOrEmpty(animParam.scriptExpression))
                {
                    GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.3f);
                    GUILayout.BeginHorizontal(Styles.clipBoxFooterStyle);
                    GUI.color = Color.white;
                    GUILayout.Space(10);
                    // GUILayout.Box(Styles.expressionIcon, GUIStyle.none, GUILayout.Width(16), GUILayout.Height(16));
                    GUILayout.Label(string.Format("<b>= </b><size=9>{0}</size>", animParam.scriptExpression));
                    GUILayout.EndHorizontal();
                }
#endif
            }

            EditorGUILayout.EndFadeGroup();
        }