Exemple #1
0
        /************************************************************************************************************************/
        #endregion
        /************************************************************************************************************************/

        /// <summary>Draws the layer's name and weight.</summary>
        protected override void DoLabelGUI(Rect area)
        {
            var label = Target.IsAdditive ? "Additive" : "Override";

            if (Target._Mask != null)
            {
                label = $"{label} ({Target._Mask.name})";
            }

            area.xMin += FoldoutIndent;

            AnimancerGUI.DoWeightLabel(ref area, Target.Weight);

            EditorGUIUtility.labelWidth -= FoldoutIndent;
            EditorGUI.LabelField(area, Target.ToString(), label);
            EditorGUIUtility.labelWidth += FoldoutIndent;
        }
Exemple #2
0
        /************************************************************************************************************************/

        /// <summary>Draws a GUI for the <see cref="Animator.runtimeAnimatorController"/> if there is one.</summary>
        private void DoNativeAnimatorControllerGUI(IAnimancerComponent target)
        {
            if (!EditorApplication.isPlaying &&
                !target.IsPlayableInitialized)
            {
                return;
            }

            var animator = target.Animator;

            if (animator == null)
            {
                return;
            }

            var controller = (AnimatorController)animator.runtimeAnimatorController;

            if (controller == null)
            {
                return;
            }

            AnimancerGUI.BeginVerticalBox(GUI.skin.box);

            var label = AnimancerGUI.GetNarrowText("Native Animator Controller");

            EditorGUI.BeginChangeCheck();
            controller = (AnimatorController)EditorGUILayout.ObjectField(label, controller, typeof(AnimatorController), true);
            if (EditorGUI.EndChangeCheck())
            {
                animator.runtimeAnimatorController = controller;
            }

            var layers = controller.layers;

            for (int i = 0; i < layers.Length; i++)
            {
                var layer = layers[i];

                var runtimeState = animator.IsInTransition(i) ?
                                   animator.GetNextAnimatorStateInfo(i) :
                                   animator.GetCurrentAnimatorStateInfo(i);

                var states      = layer.stateMachine.states;
                var editorState = GetState(states, runtimeState.shortNameHash);

                var area = AnimancerGUI.LayoutSingleLineRect(AnimancerGUI.SpacingMode.Before);

                var weight = i == 0 ? 1 : animator.GetLayerWeight(i);

                string stateName;
                if (editorState != null)
                {
                    stateName = editorState.name;

                    var isLooping = editorState.motion != null && editorState.motion.isLooping;
                    AnimancerStateDrawer <ClipState> .DoTimeHighlightBarGUI(
                        area, true, weight, runtimeState.normalizedTime *runtimeState.length, runtimeState.length, isLooping);
                }
                else
                {
                    stateName = "State Not Found";
                }

                AnimancerGUI.DoWeightLabel(ref area, weight);

                stateName = AnimancerGUI.GetNarrowText(stateName);

                EditorGUI.LabelField(area, layer.name, stateName);
            }

            AnimancerGUI.EndVerticalBox(GUI.skin.box);
        }
Exemple #3
0
        /************************************************************************************************************************/

        /// <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 shows a bar to indicate its progress.
        /// </summary>
        protected override void DoLabelGUI(Rect area)
        {
            var key              = Target.Key;
            var mainObject       = Target.MainObject;
            var isAssetUsedAsKey = key == null || ReferenceEquals(key, mainObject);

            string label;

            if (isAssetUsedAsKey)
            {
                label = "";
            }
            else
            {
                if (key is string)
                {
                    label = "\"" + key + "\"";
                }
                else
                {
                    label = key.ToString();
                }
            }

            HandleLabelClick(area);

            AnimancerGUI.DoWeightLabel(ref area, Target.Weight);

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

                mainObject = EditorGUI.ObjectField(area, label, mainObject, typeof(Object), false);

                if (EditorGUI.EndChangeCheck())
                {
                    Target.MainObject = mainObject;
                }
            }
            else
            {
                EditorGUI.LabelField(area, label, Target.ToString());
            }

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

                // Green = Playing, Yelow = Paused.
                GUI.color = Target.IsPlaying ? new Color(0.15f, 0.7f, 0.15f, 0.35f) : new Color(0.7f, 0.7f, 0.15f, 0.35f);

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

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

                GUI.DrawTexture(area, Texture2D.whiteTexture);

                GUI.color = color;
            }
        }