public void Render(Rect rect) { float contentWidth = rect.width; contentWidth -= rect.height < _viewRect.height ? 20 : 8; _scroll = GUI.BeginScrollView(rect, _scroll, _viewRect); EditorGUI.BeginChangeCheck(); GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene); _sequenceEditor.EventSelection.OnInspectorGUI(contentWidth); if (_sequenceEditor.EventSelection.Editors.Count > 0) { GUILayout.Space(10); } _sequenceEditor.TrackSelection.OnInspectorGUI(contentWidth); _sequenceEditor.TimelineSelection.OnInspectorGUI(contentWidth); _sequenceEditor.ContainerSelection.OnInspectorGUI(contentWidth); if (EditorGUI.EndChangeCheck()) { _sequenceEditor.Repaint(); } GUILayout.Space(1); if (Event.current.type == EventType.Repaint) { Rect lastElementRect = GUILayoutUtility.GetLastRect(); _viewRect = rect; _viewRect.height = Mathf.Max(_viewRect.height, lastElementRect.y + lastElementRect.height); } GUI.EndScrollView(); }
public void Render(int id, Rect rect, int hierarchyWidth, FrameRange viewRange, float pixelsPerFrame) { if (_timeline == null) { return; } rect.y += _offsetAnim.value.y; _rect = rect; float alpha = 1; if (EditorGUIUtility.hotControl == id) { rect.xMin += 5; rect.xMax -= 5; alpha = 0.7f; Color c = GUI.color; c.a = alpha; GUI.color = c; } Rect hierarchyHeaderRect = rect; hierarchyHeaderRect.width = hierarchyWidth; hierarchyHeaderRect.height = HEADER_HEIGHT; Rect timelineHeaderRect = rect; timelineHeaderRect.height = HEADER_HEIGHT; Rect trackRect = timelineHeaderRect; trackRect.yMin = timelineHeaderRect.yMax; trackRect.height = TRACK_HEIGHT; if (Event.current.type == EventType.Repaint) { GUI.color = FGUI.GetTimelineColor(); GUI.DrawTexture(timelineHeaderRect, EditorGUIUtility.whiteTexture); GUI.color = new Color(1f, 1f, 1f, alpha); } if (_showTracks) { for (int i = 0; i != _trackEditors.Count; ++i) { Vector3 upperLeft = trackRect.min; Handles.color = FGUI.GetLineColor(); if (_trackDragged != null) { if (_trackDragged == _trackEditors[i]) { Handles.DrawLine(upperLeft, upperLeft + new Vector3(trackRect.width, 0, 0)); trackRect.y += TRACK_HEIGHT; continue; } if (i < _trackDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y < trackRect.yMax) { _trackEditors[i].SetOffset(new Vector2(0, TRACK_HEIGHT)); } else if (i > _trackDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y > trackRect.yMin) { _trackEditors[i].SetOffset(new Vector2(0, -TRACK_HEIGHT)); } else { _trackEditors[i].SetOffset(Vector2.zero); } } GUI.color = new Color(0.3f, 0.3f, 0.3f, alpha); GUI.color = new Color(1f, 1f, 1f, alpha); _trackEditors[i].Render(_trackEditorIds[i], trackRect, hierarchyWidth, viewRange, pixelsPerFrame); Handles.DrawLine(upperLeft, upperLeft + new Vector3(trackRect.width, 0, 0)); trackRect.y += TRACK_HEIGHT; } if (_trackDragged != null) { Rect r = trackRect; r.y = Event.current.mousePosition.y; _trackDragged.Render(_trackEditorIds[_trackDragged.GetRuntimeObject().GetId()], r, hierarchyWidth, viewRange, pixelsPerFrame); } } Rect hierarchyLabelRect = hierarchyHeaderRect; hierarchyLabelRect.height = 20; hierarchyLabelRect.xMax = hierarchyLabelRect.xMax - 23; Rect foldoutRect = hierarchyLabelRect; foldoutRect.width = 16; hierarchyLabelRect.xMin += 16; string timelineHeaderName = _timeline.Owner != null ? _timeline.Owner.name : _timeline.name + " (Missing)"; GUI.Label(hierarchyLabelRect, new GUIContent(timelineHeaderName), FGUI.GetTimelineHeaderStyle()); _showTracks = EditorGUI.Foldout(foldoutRect, _showTracks, GUIContent.none); switch (Event.current.type) { case EventType.ContextClick: if (hierarchyHeaderRect.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); if (Selection.activeGameObject == null || PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.Prefab || PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.ModelPrefab) { menu.AddDisabledItem(new GUIContent("Change Owner")); } else { menu.AddItem(new GUIContent("Change Owner to " + Selection.activeGameObject.name), false, ChangeOwner); } menu.AddItem(new GUIContent("Duplicate Timeline"), false, DuplicateTimeline); menu.AddItem(new GUIContent("Delete Timeline"), false, DeleteTimeline); menu.AddItem(new GUIContent("Add Timeline"), false, AddTimeline); menu.ShowAsContext(); Event.current.Use(); } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == id) { SequenceEditor.Repaint(); Event.current.Use(); } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == id) { EditorGUIUtility.hotControl = 0; _offsetAnim.value = _offsetAnim.target = Vector2.zero; SequenceEditor.Repaint(); SequenceEditor.StopTimelineDrag(); Event.current.Use(); } break; case EventType.Repaint: Handles.color = FGUI.GetLineColor(); Handles.DrawLine(new Vector3(rect.xMin, rect.yMax, 0), new Vector3(rect.xMax, rect.yMax, 0)); break; case EventType.KeyDown: if (EditorGUIUtility.hotControl == id && Event.current.keyCode == KeyCode.Escape) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } break; } Rect timelineOptionsRect = hierarchyHeaderRect; timelineOptionsRect.xMin = hierarchyHeaderRect.xMax - 20; timelineOptionsRect.yMin = hierarchyHeaderRect.yMin; timelineOptionsRect.width = 14; timelineOptionsRect.height = 14; if (Event.current.type == EventType.MouseDown && timelineOptionsRect.Contains(Event.current.mousePosition)) { Event.current.Use(); GenericMenu menu = new GenericMenu(); Type[] types = typeof(FEvent).Assembly.GetTypes(); List <KeyValuePair <Type, FEventAttribute> > validTypeList = new List <KeyValuePair <Type, FEventAttribute> >(); foreach (Type t in types) { if (!typeof(FEvent).IsAssignableFrom(t)) { continue; } object[] attributes = t.GetCustomAttributes(typeof(FEventAttribute), false); if (attributes.Length == 0) { continue; } validTypeList.Add(new KeyValuePair <Type, FEventAttribute>(t, (FEventAttribute)attributes[0])); } validTypeList.Sort(delegate(KeyValuePair <Type, FEventAttribute> x, KeyValuePair <Type, FEventAttribute> y) { return(x.Value.menu.CompareTo(y.Value.menu)); }); foreach (KeyValuePair <Type, FEventAttribute> kvp in validTypeList) { menu.AddItem(new GUIContent(kvp.Value.menu), false, AddTrackMenu, kvp); } menu.ShowAsContext(); } GUI.color = FGUI.GetTextColor(); GUI.DrawTexture(timelineOptionsRect, (Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "Plus.png", typeof(Texture2D))); if (Event.current.type == EventType.MouseDown && hierarchyHeaderRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) // dragging { EditorGUIUtility.hotControl = id; _offsetAnim.value = _offsetAnim.target = new Vector2(0, hierarchyHeaderRect.yMin) - Event.current.mousePosition; SequenceEditor.StartTimelineDrag(this); Event.current.Use(); } } #if UNITY_4_5 if (_offsetAnim.isAnimating) { _sequenceEditor.Repaint(); } #endif }