UnityEditor.TimeControl.DoTimeControl C# (CSharp) Method

DoTimeControl() public method

public DoTimeControl ( Rect rect ) : void
rect UnityEngine.Rect
return void
        public void DoTimeControl(Rect rect)
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }
            Event current = Event.current;
            int controlID = GUIUtility.GetControlID(kScrubberIDHash, FocusType.Keyboard);
            Rect position = rect;
            position.height = 21f;
            Rect rect3 = position;
            rect3.xMin += 33f;
            switch (current.GetTypeForControl(controlID))
            {
                case EventType.MouseDown:
                    if (rect.Contains(current.mousePosition))
                    {
                        GUIUtility.keyboardControl = controlID;
                    }
                    if (rect3.Contains(current.mousePosition))
                    {
                        EditorGUIUtility.SetWantsMouseJumping(1);
                        GUIUtility.hotControl = controlID;
                        this.m_MouseDrag = current.mousePosition.x - rect3.xMin;
                        this.nextCurrentTime = ((this.m_MouseDrag * (this.stopTime - this.startTime)) / rect3.width) + this.startTime;
                        this.m_WrapForwardDrag = false;
                        current.Use();
                    }
                    goto Label_02C7;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        EditorGUIUtility.SetWantsMouseJumping(0);
                        GUIUtility.hotControl = 0;
                        current.Use();
                    }
                    goto Label_02C7;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl != controlID)
                    {
                        goto Label_02C7;
                    }
                    this.m_MouseDrag += current.delta.x * this.playbackSpeed;
                    if (!this.loop || (((this.m_MouseDrag >= 0f) || !this.m_WrapForwardDrag) && (this.m_MouseDrag <= rect3.width)))
                    {
                        goto Label_01E0;
                    }
                    if (this.m_MouseDrag <= rect3.width)
                    {
                        if (this.m_MouseDrag < 0f)
                        {
                            this.currentTime += this.stopTime - this.startTime;
                        }
                        break;
                    }
                    this.currentTime -= this.stopTime - this.startTime;
                    break;

                case EventType.KeyDown:
                    if (GUIUtility.keyboardControl == controlID)
                    {
                        if (current.keyCode == KeyCode.LeftArrow)
                        {
                            if ((this.currentTime - this.startTime) > 0.01f)
                            {
                                this.deltaTime = -0.01f;
                            }
                            current.Use();
                        }
                        if (current.keyCode == KeyCode.RightArrow)
                        {
                            if ((this.stopTime - this.currentTime) > 0.01f)
                            {
                                this.deltaTime = 0.01f;
                            }
                            current.Use();
                        }
                    }
                    goto Label_02C7;

                default:
                    goto Label_02C7;
            }
            this.m_WrapForwardDrag = true;
            this.m_MouseDrag = Mathf.Repeat(this.m_MouseDrag, rect3.width);
        Label_01E0:
            this.nextCurrentTime = ((Mathf.Clamp(this.m_MouseDrag, 0f, rect3.width) * (this.stopTime - this.startTime)) / rect3.width) + this.startTime;
            current.Use();
        Label_02C7:
            GUI.Box(position, GUIContent.none, s_Styles.timeScrubber);
            this.playing = GUI.Toggle(position, this.playing, !this.playing ? s_Styles.playIcon : s_Styles.pauseIcon, s_Styles.playButton);
            float x = Mathf.Lerp(rect3.x, rect3.xMax, this.normalizedTime);
            if (GUIUtility.keyboardControl == controlID)
            {
                Handles.color = new Color(1f, 0f, 0f, 1f);
            }
            else
            {
                Handles.color = new Color(1f, 0f, 0f, 0.5f);
            }
            Handles.DrawLine((Vector3) new Vector2(x, rect3.yMin), (Vector3) new Vector2(x, rect3.yMax));
            Handles.DrawLine((Vector3) new Vector2(x + 1f, rect3.yMin), (Vector3) new Vector2(x + 1f, rect3.yMax));
        }

Usage Example

        public void AvatarTimeControlGUI(Rect rect)
        {
            Rect timeControlRect = rect;

            timeControlRect.height = kTimeControlRectHeight;

            timeControl.DoTimeControl(timeControlRect);

            // Show current time in seconds:frame and in percentage
            rect.y = rect.yMax - 20;
            float time = timeControl.currentTime - timeControl.startTime;

            EditorGUI.DropShadowLabel(new Rect(rect.x, rect.y, rect.width, 20),
                                      UnityString.Format("{0,2}:{1:00} ({2:000.0%}) Frame {3}", (int)time, Repeat(Mathf.FloorToInt(time * fps), fps), timeControl.normalizedTime, Mathf.FloorToInt(timeControl.currentTime * fps))
                                      );
        }
All Usage Examples Of UnityEditor.TimeControl::DoTimeControl