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

        /// <summary>
        /// Draws controls for <see cref="AnimancerLayer.IsAdditive"/> and <see cref="AnimancerLayer._Mask"/>.
        /// </summary>
        private void DoLayerDetailsGUI()
        {
            var area = AnimancerGUI.LayoutSingleLineRect(AnimancerGUI.SpacingMode.Before);

            area = EditorGUI.IndentedRect(area);

            var labelWidth  = EditorGUIUtility.labelWidth;
            var indentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            var additiveLabel = AnimancerGUI.GetNarrowText("Is Additive");

            var additiveWidth = GUI.skin.toggle.CalculateWidth(additiveLabel);
            var maskRect      = AnimancerGUI.StealFromRight(ref area, area.width - additiveWidth);

            // Additive.
            EditorGUIUtility.labelWidth = AnimancerGUI.CalculateLabelWidth(additiveLabel);
            Target.IsAdditive           = EditorGUI.Toggle(area, additiveLabel, Target.IsAdditive);

            // Mask.
            using (ObjectPool.Disposable.AcquireContent(out var label, "Mask"))
            {
                EditorGUIUtility.labelWidth = AnimancerGUI.CalculateLabelWidth(label.text);
                EditorGUI.BeginChangeCheck();
                Target._Mask = (AvatarMask)EditorGUI.ObjectField(maskRect, label, Target._Mask, typeof(AvatarMask), false);
                if (EditorGUI.EndChangeCheck())
                {
                    Target.SetMask(Target._Mask);
                }
            }

            EditorGUI.indentLevel       = indentLevel;
            EditorGUIUtility.labelWidth = labelWidth;
        }
Exemple #2
0
        private void DoLoopCounterGUI(ref Rect area, float length)
        {
            if (_LoopCounterCache == null)
            {
                _LoopCounterCache = new ConversionCache <int, string>((x) => "x" + x);
            }

            string label;
            var    normalizedTime = Target.Time / length;

            if (float.IsNaN(normalizedTime))
            {
                label = "NaN";
            }
            else
            {
                var loops = (int)Math.Abs(Target.Time / length);
                label = _LoopCounterCache.Convert(loops);
            }

            var width = AnimancerGUI.CalculateLabelWidth(label);

            var labelArea = AnimancerGUI.StealFromRight(ref area, width);

            GUI.Label(labelArea, label);
        }
        /************************************************************************************************************************/

        /// <summary>Draws all `states` in the given list.</summary>
        private void DoStatesGUI(string label, List <AnimancerState> states, IAnimancerComponent owner)
        {
            var area = AnimancerGUI.LayoutSingleLineRect();

            var width = AnimancerGUI.CalculateLabelWidth("Weight");

            GUI.Label(AnimancerGUI.StealFromRight(ref area, width), "Weight");

            EditorGUI.LabelField(area, label, states.Count.ToString());

            EditorGUI.indentLevel++;
            for (int i = 0; i < states.Count; i++)
            {
                DoStateGUI(states[i], owner);
            }
            EditorGUI.indentLevel--;
        }
Exemple #4
0
        /************************************************************************************************************************/

        private void DoRootGUI(AnimancerPlayable playable)
        {
            var labelWidth = EditorGUIUtility.labelWidth;

            AnimancerGUI.BeginVerticalBox(GUI.skin.box);

            using (ObjectPool.Disposable.AcquireContent(out var label, "Is Graph Playing"))
            {
                const string SpeedLabel = "Speed";

                var isPlayingWidth = AnimancerGUI.CalculateLabelWidth(label.text);
                var speedWidth     = AnimancerGUI.CalculateLabelWidth(SpeedLabel);

                var area          = AnimancerGUI.LayoutSingleLineRect();
                var isPlayingArea = area;
                var speedArea     = area;
                isPlayingArea.width = isPlayingWidth + AnimancerGUI.ToggleWidth;
                speedArea.xMin      = isPlayingArea.xMax;

                EditorGUIUtility.labelWidth = isPlayingWidth;
                playable.IsGraphPlaying     = EditorGUI.Toggle(isPlayingArea, label, playable.IsGraphPlaying);

                EditorGUIUtility.labelWidth = speedWidth;
                EditorGUI.BeginChangeCheck();
                var speed = EditorGUI.FloatField(speedArea, SpeedLabel, playable.Speed);
                if (EditorGUI.EndChangeCheck())
                {
                    playable.Speed = speed;
                }
                if (AnimancerGUI.TryUseClickEvent(speedArea, 2))
                {
                    playable.Speed = playable.Speed != 1 ? 1 : 0;
                }
            }

            AnimancerGUI.EndVerticalBox(GUI.skin.box);
            EditorGUIUtility.labelWidth = labelWidth;

            CheckContextMenu(GUILayoutUtility.GetLastRect(), playable);
        }
Exemple #5
0
        /************************************************************************************************************************/

        /// <summary>
        /// Draws controls for <see cref="AnimancerState.IsPlaying"/>, <see cref="AnimancerNode.Speed"/>, and
        /// <see cref="AnimancerNode.Weight"/>.
        /// </summary>
        protected void DoNodeDetailsGUI()
        {
            var area = AnimancerGUI.LayoutSingleLineRect(AnimancerGUI.SpacingMode.Before);

            area.xMin += EditorGUI.indentLevel * AnimancerGUI.IndentSize;
            var xMin = area.xMin;
            var xMax = area.xMax;

            var labelWidth  = EditorGUIUtility.labelWidth;
            var indentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            // Is Playing.
            var state = Target as AnimancerState;

            if (state != null)
            {
                var label = AnimancerGUI.BeginTightLabel("Is Playing");
                area.width      = EditorGUIUtility.labelWidth + 16;
                state.IsPlaying = EditorGUI.Toggle(area, label, state.IsPlaying);
                AnimancerGUI.EndTightLabel();

                area.x   += area.width;
                area.xMax = xMax;
            }

            AnimancerGUI.SplitHorizontally(area, "Speed", "Weight",
                                           out var speedWidth, out var weightWidth, out var speedRect, out var weightRect);

            // Speed.
            EditorGUIUtility.labelWidth = speedWidth;
            EditorGUI.BeginChangeCheck();
            var speed = EditorGUI.FloatField(speedRect, "Speed", Target.Speed);

            if (EditorGUI.EndChangeCheck())
            {
                Target.Speed = speed;
            }
            if (AnimancerGUI.TryUseClickEvent(speedRect, 2))
            {
                Target.Speed = Target.Speed != 1 ? 1 : 0;
            }

            // Weight.
            EditorGUIUtility.labelWidth = weightWidth;
            EditorGUI.BeginChangeCheck();
            var weight = EditorGUI.FloatField(weightRect, "Weight", Target.Weight);

            if (EditorGUI.EndChangeCheck())
            {
                SetWeight(Mathf.Max(weight, 0));
            }
            if (AnimancerGUI.TryUseClickEvent(weightRect, 2))
            {
                SetWeight(Target.Weight != 1 ? 1 : 0);
            }

            // Not really sure why this is necessary.
            // It allows the dummy ID added when the Real Speed is hidden to work properly.
            GUIUtility.GetControlID(FocusType.Passive);

            // Real Speed (Mixer Synchronization changes the internal Playable Speed without setting the State Speed).
            speed = (float)Target._Playable.GetSpeed();
            if (Target.Speed != speed)
            {
                using (new EditorGUI.DisabledScope(true))
                {
                    area      = AnimancerGUI.LayoutSingleLineRect(AnimancerGUI.SpacingMode.Before);
                    area.xMin = xMin;

                    var label = AnimancerGUI.BeginTightLabel("Real Speed");
                    EditorGUIUtility.labelWidth = AnimancerGUI.CalculateLabelWidth(label);
                    EditorGUI.FloatField(area, label, speed);
                    AnimancerGUI.EndTightLabel();
                }
            }
            else// Add a dummy ID so that subsequent IDs don't change when the Real Speed appears or disappears.
            {
                GUIUtility.GetControlID(FocusType.Passive);
            }

            EditorGUI.indentLevel       = indentLevel;
            EditorGUIUtility.labelWidth = labelWidth;

            DoFadeDetailsGUI();
        }