Exemplo n.º 1
0
        /************************************************************************************************************************/

        private void SetPreviewTime(Event currentGUIEvent)
        {
            if (_Duration > 0)
            {
                var seconds = PixelsToSeconds(currentGUIEvent.mousePosition.x);
                TransitionPreviewWindow.SetPreviewNormalizedTime(seconds / _Duration);
            }
        }
Exemplo n.º 2
0
        /// <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();
                }
            }
        }