Example #1
0
        /************************************************************************************************************************/

        /// <summary>
        /// Draws the name and other details of the <see cref="Layer"/> in the GUI.
        /// </summary>
        private void DoHeaderGUI()
        {
            if (Layer.Root.LayerCount <= 1 && Layer.Weight == 1 && Layer._Mask == null)
            {
                return;
            }

            var area = AnimancerEditorUtilities.GetRect();

            const float FoldoutIndent = 12;

            area.xMin += FoldoutIndent;
            Layer._IsInspectorExpanded = EditorGUI.Foldout(area, Layer._IsInspectorExpanded, GUIContent.none, true);

            AnimancerEditorUtilities.DoWeightLabelGUI(ref area, Layer.Weight);

            var label = Layer.IsAdditive ? "Additive" : "Override";

            if (Layer._Mask != null)
            {
                label = string.Concat(label, " (", Layer._Mask.name, ")");
            }

            EditorGUIUtility.labelWidth -= FoldoutIndent;
            EditorGUI.LabelField(area, Layer.Name, label);
            EditorGUIUtility.labelWidth += FoldoutIndent;

            if (Layer._IsInspectorExpanded)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(FoldoutIndent);
                GUILayout.BeginVertical();

                EditorGUI.indentLevel++;

                Layer.IsAdditive = EditorGUILayout.Toggle("Is Additive", Layer.IsAdditive);

                EditorGUI.BeginChangeCheck();
                Layer._Mask = (AvatarMask)EditorGUILayout.ObjectField("Mask", Layer._Mask, typeof(AvatarMask), false);
                if (EditorGUI.EndChangeCheck())
                {
                    Layer.SetMask(Layer._Mask);
                }

                EditorGUI.BeginChangeCheck();
                var weight = EditorGUILayout.FloatField("Weight", Layer.Weight);
                if (EditorGUI.EndChangeCheck())
                {
                    Layer.Weight = weight;
                }

                area = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
                Layer.DoFadeDetailsGUI(area);

                EditorGUI.indentLevel--;

                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
            }
        }
        /************************************************************************************************************************/

        /// <summary>
        /// Draws the state's main label: an <see cref="Object"/> field if it has a
        /// <see cref="AnimancerState.MainObject"/>, otherwise just a simple text label.
        /// <para></para>
        /// Also handles Ctrl + Click on the label to CrossFade the animation and shows a bar to indicate its progress.
        /// </summary>
        protected virtual void DoLabelGUI(ref Rect area, string label)
        {
            var currentEvent = Event.current;

            if (currentEvent.type == EventType.MouseUp &&
                currentEvent.control &&
                area.Contains(currentEvent.mousePosition))
            {
                var fadeDuration = State.CalculateEditorFadeDuration(AnimancerPlayable.DefaultFadeDuration);
                State.Root.CrossFade(State, fadeDuration);
                currentEvent.Use();
            }

            AnimancerEditorUtilities.DoWeightLabelGUI(ref area, State.Weight);

            if (!ReferenceEquals(State.MainObject, null))
            {
                EditorGUI.BeginChangeCheck();

                EditorGUI.ObjectField(area, label, State.MainObject, typeof(Object), false);

                if (EditorGUI.EndChangeCheck())
                {
                    Debug.LogWarning("Assigning an asset to a state using the inspector is not supported." +
                                     " You can drag and drop an AnimationClip onto the layer header if you wish to create a new state for it.");
                }
            }
            else
            {
                EditorGUI.LabelField(area, label, State.ToString());
            }

            // Highlight a section of the label based on the time like a loading bar.
            if (State.HasLength && (State.IsPlaying || State.Time != 0))
            {
                var color = GUI.color;

                // Green = Playing, Yelow = Paused.
                GUI.color = State.IsPlaying ? new Color(0.25f, 1, 0.25f, 0.25f) : new Color(1, 1, 0.25f, 0.25f);

                area.xMin  += AnimancerEditorUtilities.IndentSize;
                area.width -= 18;

                float length;
                float wrappedTime = GetWrappedTime(out length);
                if (length > 0)
                {
                    area.width *= Mathf.Clamp01(wrappedTime / length);
                }

                GUI.Box(area, GUIContent.none);

                GUI.color = color;
            }
        }