/// <summary> /// If the `property` is a "Start Time" field, this method draws it as well as the "End Time" below it and /// returns true. /// </summary> public static bool TryDoStartTimeField(ref Rect area, SerializedProperty rootProperty, SerializedProperty property, GUIContent label) { if (!property.propertyPath.EndsWith("." + NormalizedStartTimeFieldName)) { return(false); } // Start Time. label.text = AnimancerGUI.GetNarrowText("Start Time"); var length = Context.MaximumDuration; var defaultStartTime = AnimancerEvent.Sequence.GetDefaultNormalizedStartTime(Context.Transition.Speed); AnimancerGUI.DoOptionalTimeField(ref area, label, property, true, length, defaultStartTime); AnimancerGUI.NextVerticalArea(ref area); // End Time. var events = rootProperty.FindPropertyRelative("_Events"); using (var context = EventSequenceDrawer.Context.Get(events)) { var areaCopy = area; var index = Mathf.Max(0, context.TimeCount - 1); string callbackLabel; EventSequenceDrawer.DoEventTimeGUI(ref areaCopy, context, index, true, out callbackLabel); } return(true); }
/************************************************************************************************************************/ /// <summary> /// Draws the `property` GUI in relation to the `rootProperty` which was passed into <see cref="OnGUI"/>. /// </summary> protected virtual void DoPropertyGUI(ref Rect area, SerializedProperty rootProperty, SerializedProperty property, GUIContent label) { // If we keep using the GUIContent that was passed into OnGUI then GetPropertyHeight will change it to // match the 'property' which we don't want. label = AnimancerGUI.TempContent(label.text, label.tooltip, false); area.height = EditorGUI.GetPropertyHeight(property, label, true); if (property.propertyPath.EndsWith("._FadeDuration")) { var length = Context.MaximumDuration; AnimancerGUI.DoOptionalTimeField(ref area, label, property, false, length, AnimancerPlayable.DefaultFadeDuration, false); if (property.floatValue < 0) { property.floatValue = 0; } return; } if (property.propertyPath.EndsWith("._Speed")) { AnimancerGUI.DoOptionalTimeField(ref area, label, property, true, float.NaN, 1); return; } if (TryDoStartTimeField(ref area, rootProperty, property, label)) { return; } if (!EditorGUIUtility.hierarchyMode) { EditorGUI.indentLevel++; } EditorGUI.PropertyField(area, property, label, true); if (!EditorGUIUtility.hierarchyMode) { EditorGUI.indentLevel--; } }
/// <summary>Draws the time field for the event at the specified `index`.</summary> public static void DoEventTimeGUI(ref Rect area, Context context, int index, bool autoSort, out string callbackLabel) { EditorGUI.BeginChangeCheck(); area.height = AnimancerGUI.LineHeight; var timeArea = area; AnimancerGUI.NextVerticalArea(ref area); GUIContent timeLabel; float defaultTime; bool isEndEvent; GetEventLabels(index, context, out timeLabel, out callbackLabel, out defaultTime, out isEndEvent); var length = context.TransitionContext.MaximumDuration; float normalizedTime; if (index < context.TimeCount) { var timeProperty = context.GetTime(index); var wasEditingTextField = EditorGUIUtility.editingTextField; if (!wasEditingTextField) { _PreviousTime = float.NaN; } EditorGUI.BeginChangeCheck(); timeLabel = EditorGUI.BeginProperty(area, timeLabel, timeProperty); normalizedTime = AnimancerGUI.DoOptionalTimeField( ref timeArea, timeLabel, timeProperty.floatValue, true, length, defaultTime); EditorGUI.EndProperty(); var isEditingTextField = EditorGUIUtility.editingTextField; if (EditorGUI.EndChangeCheck() || (wasEditingTextField && !isEditingTextField)) { if (isEndEvent) { timeProperty.floatValue = normalizedTime; } else if (float.IsNaN(normalizedTime)) { RemoveEvent(context, index); AnimancerGUI.Deselect(); } else if (!autoSort && isEditingTextField) { _PreviousTime = normalizedTime; } else { if (!float.IsNaN(_PreviousTime)) { if (Event.current.keyCode != KeyCode.Escape) { normalizedTime = _PreviousTime; AnimancerGUI.Deselect(); } _PreviousTime = float.NaN; } WrapEventTime(context, ref normalizedTime); timeProperty.floatValue = normalizedTime; if (autoSort) { SortEvents(context); } } GUI.changed = true; } } else// Dummy End Event. { Debug.Assert(index == 0, "This is assumed to be a dummy end event, which should only be at index 0"); EditorGUI.BeginChangeCheck(); EditorGUI.BeginProperty(timeArea, GUIContent.none, context.Times); normalizedTime = AnimancerGUI.DoOptionalTimeField( ref timeArea, timeLabel, float.NaN, true, length, defaultTime, true); EditorGUI.EndProperty(); if (EditorGUI.EndChangeCheck() && !float.IsNaN(normalizedTime)) { context.TimeCount = 1; var timeProperty = context.GetTime(0); timeProperty.floatValue = normalizedTime; } } if (EditorGUI.EndChangeCheck()) { TransitionPreviewWindow.SetPreviewNormalizedTime(normalizedTime); if (Event.current.type != EventType.Layout) { GUIUtility.ExitGUI(); } } }