コード例 #1
0
        /************************************************************************************************************************/

        /// <summary>
        /// Draws controls for <see cref="AnimancerNode.FadeSpeed"/> and <see cref="AnimancerNode.TargetWeight"/>.
        /// </summary>
        private void DoFadeDetailsGUI()
        {
            var area = AnimancerGUI.LayoutSingleLineRect(AnimancerGUI.SpacingMode.Before);

            area = EditorGUI.IndentedRect(area);

            var speedLabel  = AnimancerGUI.GetNarrowText("Fade Speed");
            var targetLabel = AnimancerGUI.GetNarrowText("Target Weight");

            float speedWidth, weightWidth;
            Rect  speedRect, weightRect;

            AnimancerGUI.SplitHorizontally(area, speedLabel, targetLabel,
                                           out speedWidth, out weightWidth, out speedRect, out weightRect);

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

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginChangeCheck();

            // Fade Speed.
            EditorGUIUtility.labelWidth = speedWidth;
            Target.FadeSpeed            = EditorGUI.DelayedFloatField(speedRect, speedLabel, Target.FadeSpeed);
            if (AnimancerGUI.TryUseClickEvent(speedRect, 2))
            {
                Target.FadeSpeed = Target.FadeSpeed != 0 ?
                                   0 :
                                   Math.Abs(Target.Weight - Target.TargetWeight) / AnimancerPlayable.DefaultFadeDuration;
            }

            // Target Weight.
            EditorGUIUtility.labelWidth = weightWidth;
            Target.TargetWeight         = EditorGUI.FloatField(weightRect, targetLabel, Target.TargetWeight);
            if (AnimancerGUI.TryUseClickEvent(weightRect, 2))
            {
                if (Target.TargetWeight != Target.Weight)
                {
                    Target.TargetWeight = Target.Weight;
                }
                else if (Target.TargetWeight != 1)
                {
                    Target.TargetWeight = 1;
                }
                else
                {
                    Target.TargetWeight = 0;
                }
            }

            if (EditorGUI.EndChangeCheck() && Target.FadeSpeed != 0)
            {
                Target.StartFade(Target.TargetWeight, 1 / Target.FadeSpeed);
            }

            EditorGUI.indentLevel       = indentLevel;
            EditorGUIUtility.labelWidth = labelWidth;
        }
コード例 #2
0
ファイル: AnimancerNodeDrawer.cs プロジェクト: malering/ET
        /************************************************************************************************************************/

        /// <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();
        }
コード例 #3
0
        /************************************************************************************************************************/

        /// <summary>
        /// Draws controls for <see cref="AnimancerState.IsPlaying"/>, <see cref="AnimancerNode.Speed"/>, and
        /// <see cref="AnimancerNode.Weight"/>.
        /// </summary>
        protected void DoNodeDetailsGUI()
        {
            var labelWidth = EditorGUIUtility.labelWidth;

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

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

            var indentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            var right = area.xMax;

            // 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 = right;
            }

            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())
            {
                Target.Weight = Mathf.Max(weight, 0);
            }
            if (AnimancerGUI.TryUseClickEvent(weightRect, 2))
            {
                Target.Weight = Target.Weight != 1 ? 1 : 0;
            }

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

            DoFadeDetailsGUI();
        }