public void DoTimeControl(Rect rect) { if (TimeControl.s_Styles == null) TimeControl.s_Styles = new TimeControl.Styles(); Event current = Event.current; int controlId = GUIUtility.GetControlID(TimeControl.kScrubberIDHash, FocusType.Keyboard); Rect position = rect; position.height = 21f; Rect rect1 = position; rect1.xMin += 33f; switch (current.GetTypeForControl(controlId)) { case EventType.MouseDown: if (rect.Contains(current.mousePosition)) GUIUtility.keyboardControl = controlId; if (rect1.Contains(current.mousePosition)) { EditorGUIUtility.SetWantsMouseJumping(1); GUIUtility.hotControl = controlId; this.m_MouseDrag = current.mousePosition.x - rect1.xMin; this.nextCurrentTime = this.m_MouseDrag * (this.stopTime - this.startTime) / rect1.width + this.startTime; this.m_WrapForwardDrag = false; current.Use(); break; } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlId) { EditorGUIUtility.SetWantsMouseJumping(0); GUIUtility.hotControl = 0; current.Use(); break; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlId) { this.m_MouseDrag += current.delta.x * this.playbackSpeed; if (this.loop && ((double) this.m_MouseDrag < 0.0 && this.m_WrapForwardDrag || (double) this.m_MouseDrag > (double) rect1.width)) { if ((double) this.m_MouseDrag > (double) rect1.width) this.currentTime -= this.stopTime - this.startTime; else if ((double) this.m_MouseDrag < 0.0) this.currentTime += this.stopTime - this.startTime; this.m_WrapForwardDrag = true; this.m_MouseDrag = Mathf.Repeat(this.m_MouseDrag, rect1.width); } this.nextCurrentTime = Mathf.Clamp(this.m_MouseDrag, 0.0f, rect1.width) * (this.stopTime - this.startTime) / rect1.width + this.startTime; current.Use(); break; } break; case EventType.KeyDown: if (GUIUtility.keyboardControl == controlId) { if (current.keyCode == KeyCode.LeftArrow) { if ((double) this.currentTime - (double) this.startTime > 0.00999999977648258) this.deltaTime = -0.01f; current.Use(); } if (current.keyCode == KeyCode.RightArrow) { if ((double) this.stopTime - (double) this.currentTime > 0.00999999977648258) this.deltaTime = 0.01f; current.Use(); break; } break; } break; } GUI.Box(position, GUIContent.none, TimeControl.s_Styles.timeScrubber); this.playing = GUI.Toggle(position, this.playing, !this.playing ? TimeControl.s_Styles.playIcon : TimeControl.s_Styles.pauseIcon, TimeControl.s_Styles.playButton); float x = Mathf.Lerp(rect1.x, rect1.xMax, this.normalizedTime); Handles.color = GUIUtility.keyboardControl != controlId ? new Color(1f, 0.0f, 0.0f, 0.5f) : new Color(1f, 0.0f, 0.0f, 1f); Handles.DrawLine((Vector3) new Vector2(x, rect1.yMin), (Vector3) new Vector2(x, rect1.yMax)); Handles.DrawLine((Vector3) new Vector2(x + 1f, rect1.yMin), (Vector3) new Vector2(x + 1f, rect1.yMax)); }
public void DoTimeControl(Rect rect) { if (TimeControl.s_Styles == null) { TimeControl.s_Styles = new TimeControl.Styles(); } Event current = Event.current; int controlID = GUIUtility.GetControlID(TimeControl.kScrubberIDHash, FocusType.Keyboard); Rect rect2 = rect; rect2.height = 21f; Rect rect3 = rect2; 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(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID) { EditorGUIUtility.SetWantsMouseJumping(0); GUIUtility.hotControl = 0; current.Use(); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlID) { this.m_MouseDrag += current.delta.x * this.playbackSpeed; if (this.loop && ((this.m_MouseDrag < 0f && this.m_WrapForwardDrag) || this.m_MouseDrag > rect3.width)) { if (this.m_MouseDrag > rect3.width) { this.currentTime -= this.stopTime - this.startTime; } else if (this.m_MouseDrag < 0f) { this.currentTime += this.stopTime - this.startTime; } this.m_WrapForwardDrag = true; this.m_MouseDrag = Mathf.Repeat(this.m_MouseDrag, rect3.width); } this.nextCurrentTime = Mathf.Clamp(this.m_MouseDrag, 0f, rect3.width) * (this.stopTime - this.startTime) / rect3.width + this.startTime; current.Use(); } 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(); } } break; } GUI.Box(rect2, GUIContent.none, TimeControl.s_Styles.timeScrubber); this.playing = GUI.Toggle(rect2, this.playing, (!this.playing) ? TimeControl.s_Styles.playIcon : TimeControl.s_Styles.pauseIcon, TimeControl.s_Styles.playButton); float x = Mathf.Lerp(rect3.x, rect3.xMax, this.normalizedTime); TimeArea.DrawPlayhead(x, rect3.yMin, rect3.yMax, 2f, (GUIUtility.keyboardControl != controlID) ? 0.5f : 1f); }
public void DoTimeControl(Rect rect) { if (TimeControl.s_Styles == null) { TimeControl.s_Styles = new TimeControl.Styles(); } Event current = Event.current; int controlID = GUIUtility.GetControlID(TimeControl.kScrubberIDHash, FocusType.Keyboard); Rect rect2 = rect; rect2.height = 21f; Rect rect3 = rect2; 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(); } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID) { EditorGUIUtility.SetWantsMouseJumping(0); GUIUtility.hotControl = 0; current.Use(); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlID) { this.m_MouseDrag += current.delta.x * this.playbackSpeed; if (this.loop && ((this.m_MouseDrag < 0f && this.m_WrapForwardDrag) || this.m_MouseDrag > rect3.width)) { if (this.m_MouseDrag > rect3.width) { this.currentTime -= this.stopTime - this.startTime; } else { if (this.m_MouseDrag < 0f) { this.currentTime += this.stopTime - this.startTime; } } this.m_WrapForwardDrag = true; this.m_MouseDrag = Mathf.Repeat(this.m_MouseDrag, rect3.width); } this.nextCurrentTime = Mathf.Clamp(this.m_MouseDrag, 0f, rect3.width) * (this.stopTime - this.startTime) / rect3.width + this.startTime; current.Use(); } 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(); } } break; } GUI.Box(rect2, GUIContent.none, TimeControl.s_Styles.timeScrubber); this.playing = GUI.Toggle(rect2, this.playing, (!this.playing) ? TimeControl.s_Styles.playIcon : TimeControl.s_Styles.pauseIcon, TimeControl.s_Styles.playButton); float num = 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(new Vector2(num, rect3.yMin), new Vector2(num, rect3.yMax)); Handles.DrawLine(new Vector2(num + 1f, rect3.yMin), new Vector2(num + 1f, rect3.yMax)); }
public void DoTimeControl(Rect rect) { if (TimeControl.s_Styles == null) { TimeControl.s_Styles = new TimeControl.Styles(); } Event current = Event.current; int controlId = GUIUtility.GetControlID(TimeControl.kScrubberIDHash, FocusType.Keyboard); Rect position = rect; position.height = 21f; Rect rect1 = position; rect1.xMin += 33f; switch (current.GetTypeForControl(controlId)) { case EventType.MouseDown: if (rect.Contains(current.mousePosition)) { GUIUtility.keyboardControl = controlId; } if (rect1.Contains(current.mousePosition)) { EditorGUIUtility.SetWantsMouseJumping(1); GUIUtility.hotControl = controlId; this.m_MouseDrag = current.mousePosition.x - rect1.xMin; this.nextCurrentTime = this.m_MouseDrag * (this.stopTime - this.startTime) / rect1.width + this.startTime; this.m_WrapForwardDrag = false; current.Use(); break; } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlId) { EditorGUIUtility.SetWantsMouseJumping(0); GUIUtility.hotControl = 0; current.Use(); break; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlId) { this.m_MouseDrag += current.delta.x * this.playbackSpeed; if (this.loop && ((double)this.m_MouseDrag < 0.0 && this.m_WrapForwardDrag || (double)this.m_MouseDrag > (double)rect1.width)) { if ((double)this.m_MouseDrag > (double)rect1.width) { this.currentTime -= this.stopTime - this.startTime; } else if ((double)this.m_MouseDrag < 0.0) { this.currentTime += this.stopTime - this.startTime; } this.m_WrapForwardDrag = true; this.m_MouseDrag = Mathf.Repeat(this.m_MouseDrag, rect1.width); } this.nextCurrentTime = Mathf.Clamp(this.m_MouseDrag, 0.0f, rect1.width) * (this.stopTime - this.startTime) / rect1.width + this.startTime; current.Use(); break; } break; case EventType.KeyDown: if (GUIUtility.keyboardControl == controlId) { if (current.keyCode == KeyCode.LeftArrow) { if ((double)this.currentTime - (double)this.startTime > 0.00999999977648258) { this.deltaTime = -0.01f; } current.Use(); } if (current.keyCode == KeyCode.RightArrow) { if ((double)this.stopTime - (double)this.currentTime > 0.00999999977648258) { this.deltaTime = 0.01f; } current.Use(); break; } break; } break; } GUI.Box(position, GUIContent.none, TimeControl.s_Styles.timeScrubber); this.playing = GUI.Toggle(position, this.playing, !this.playing ? TimeControl.s_Styles.playIcon : TimeControl.s_Styles.pauseIcon, TimeControl.s_Styles.playButton); float x = Mathf.Lerp(rect1.x, rect1.xMax, this.normalizedTime); Handles.color = GUIUtility.keyboardControl != controlId ? new Color(1f, 0.0f, 0.0f, 0.5f) : new Color(1f, 0.0f, 0.0f, 1f); Handles.DrawLine((Vector3) new Vector2(x, rect1.yMin), (Vector3) new Vector2(x, rect1.yMax)); Handles.DrawLine((Vector3) new Vector2(x + 1f, rect1.yMin), (Vector3) new Vector2(x + 1f, rect1.yMax)); }