/************************************************************************************************************************/ /// <summary>Draws a slider for controlling the current <see cref="AnimancerState.Time"/>.</summary> private void DoTimeSliderGUI() { if (Target.Length <= 0) { return; } float length; var time = GetWrappedTime(out length); if (length == 0) { return; } var area = AnimancerGUI.LayoutSingleLineRect(AnimancerGUI.SpacingMode.Before); var normalized = DoNormalizedTimeToggle(ref area); string label; float max; if (normalized) { label = "Normalized Time"; time /= length; max = 1; } else { label = "Time"; max = length; } DoLoopCounterGUI(ref area, length); EditorGUI.BeginChangeCheck(); label = AnimancerGUI.BeginTightLabel(label); time = EditorGUI.Slider(area, label, time, 0, max); AnimancerGUI.EndTightLabel(); if (AnimancerGUI.TryUseClickEvent(area, 2)) { time = 0; } if (EditorGUI.EndChangeCheck()) { if (normalized) { Target.NormalizedTime = time; } else { Target.Time = time; } } }
/************************************************************************************************************************/ /// <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(); }
/************************************************************************************************************************/ /// <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(); }