public override void Init(FObject obj, FEditor owner) { base.Init(obj, owner); Type evtType = obj.GetType(); object[] customAttributes = evtType.GetCustomAttributes(typeof(FEventAttribute), false); if (customAttributes.Length > 0) { _isSingleFrame = ((FEventAttribute)customAttributes[0]).isSingleFrame; } if (_isSingleFrame && Evt.FrameRange.Length != 1) { FrameRange range = Evt.FrameRange; range.Length = 1; Evt.FrameRange = range; } if (_singleFrameStyle == null) { _singleFrameStyle = FUtility.GetFluxSkin().GetStyle("SingleFrame"); } GUIContent singleWidth = new GUIContent(FUtility.GetFluxTexture("SingleFrame_Active.png")); _singleSize = _singleFrameStyle.CalcSize(singleWidth); }
private void AddContainer() { GenericMenu menu = new GenericMenu(); bool hasDefaultContainers = false; List <FColorSetting> defaultContainers = FUtility.GetSettings().DefaultContainers; foreach (FColorSetting colorSetting in defaultContainers) { if (string.IsNullOrEmpty(colorSetting._str)) { continue; } menu.AddItem(new GUIContent(colorSetting._str), false, CreateContainer, colorSetting); hasDefaultContainers = true; } if (!hasDefaultContainers) { _sequenceWindow.GetSequenceEditor().CreateContainer(new FColorSetting("Default", FGUI.DefaultContainerColor())); return; } menu.AddSeparator(null); menu.AddItem(new GUIContent("[Default New Container]"), false, CreateContainer, new FColorSetting("Default", FGUI.DefaultContainerColor())); menu.ShowAsContext(); }
// public List<FTrackEditor> _trackEditors = new List<FTrackEditor>(); // [SerializeField] // private int[] _trackEditorIds = new int[0]; // [SerializeField] // private AnimVector3 _offsetAnim = new AnimVector3(); // private FTrackEditor _trackDragged = null; public override void Init(FObject obj, FEditor owner) { base.Init(obj, owner); if (Timeline.Owner == null) { Timeline.Awake(); } Editors.Clear(); List <FTrack> tracks = Timeline.Tracks; for (int i = 0; i < tracks.Count; ++i) { FTrack track = tracks[i]; FTrackEditor trackEditor = ContainerEditor.SequenceEditor.GetEditor <FTrackEditor>(track); trackEditor.Init(track, this); Editors.Add(trackEditor); } _icon = new GUIContent(FUtility.GetFluxTexture("Plus.png")); // _offsetAnim.valueChanged.AddListener( ContainerEditor.SequenceEditor.Repaint ); }
public void Pause() { // Debug.Log ("Pause"); _sequence.Pause(); _isPlaying = false; FUtility.RepaintGameView(); }
public void GoToFrame(int frame) { _window.GetSequenceEditor().SetCurrentFrame(frame); if (_window.IsPlaying) { _window.Pause(); } FUtility.RepaintGameView(); }
private static void Rescale(FEvent evt, float scaleFactor) { FrameRange newFrameRange = evt.FrameRange; newFrameRange.Start = Mathf.RoundToInt(newFrameRange.Start * scaleFactor); newFrameRange.End = Mathf.RoundToInt(newFrameRange.End * scaleFactor); FUtility.Rescale(evt, newFrameRange); }
public FSequenceWindowHeader(FSequenceEditorWindow sequenceWindow) { _sequenceWindow = sequenceWindow; RebuildSequenceList(); EditorApplication.hierarchyWindowChanged += OnHierarchyChanged; _addContainerLabel.image = FUtility.GetFluxTexture("AddFolder.png"); }
protected override void OnEnable() { base.OnEnable(); _isDynamic = serializedObject.FindProperty("_isDynamic"); _target = serializedObject.FindProperty("_target"); Transform[] objs = FUtility.FindObjects<Transform>(); _paths = new List<string>(); _targetDict.Clear(); for (int i = 0; i < objs.Length; i++) { if (objs[i].parent == null) _paths.AddRange(GetTransformPath(objs[i])); } string path = _paths[_selectedNodeIndex]; if (_selectedNodeIndex < _paths.Count && _targetDict.ContainsKey(path)) _target.objectReferenceValue = _targetDict[path]; _pathNames = new GUIContent[_paths.Count]; for (int i = 0; i < _paths.Count; i++) _pathNames[i] = new GUIContent(_paths[i]); _zone = serializedObject.FindProperty("_zone"); _zones = new List<FHitZone>(FUtility.FindObjects<FHitZone>()); _zones.Sort(delegate (FHitZone a, FHitZone b) { return a.name.CompareTo(b.name); }); if (_zone.objectReferenceValue == null && _zones.Count > 0) { _selectedZoneIndex = 0; _zone.objectReferenceValue = _zones[0]; } else _selectedZoneIndex = _zones.FindIndex((select) => select.name == _zone.objectReferenceValue.name); _zoneNames = new GUIContent[_zones.Count]; for (int i = 0; i != _zones.Count; ++i) _zoneNames[i] = new GUIContent(_zones[i].Text); var staticHit = (FHitCheck)target; _sequence = serializedObject.FindProperty("_sequence"); _sequences = new List<FSequence>(FUtility.FindObjects<FSequence>()); _sequences.Remove(staticHit.Sequence); _sequences.Sort(delegate (FSequence x, FSequence y) { return x.name.CompareTo(y.name); }); if (_sequence.objectReferenceValue == null && _sequences.Count > 0) { _selectedSequenceIndex = 0; _sequence.objectReferenceValue = _sequences[0]; } else _selectedSequenceIndex = _sequences.FindIndex((select) => select.name == _sequence.objectReferenceValue.name); _sequenceNames = new GUIContent[_sequences.Count]; for (int i = 0; i != _sequences.Count; ++i) _sequenceNames[i] = new GUIContent(_sequences[i].name); serializedObject.ApplyModifiedProperties(); }
private void LoadSequence() { var path = EditorUtility.OpenFilePanel("SelectSkills", FSettings.SequenceSavePath, "prefab"); if (!string.IsNullOrEmpty(path)) { var assetPath = FUtility.GetAssetPathFromFullPath(path); var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath); var go = GameObject.Instantiate(prefab); go.name = FUtility.RemoveCloneStr(go.name); var sequence = go.GetComponent <FSequence>(); _sequenceWindow.GetSequenceEditor().OpenSequence(sequence); } }
void OnEnable() { instance = this; wantsMouseMove = true; minSize = new Vector2(450, 300); _windowHeader = new FSequenceWindowHeader(this); _toolbar = new FSequenceWindowToolbar(this); _windowRect = new Rect(); FUtility.LoadPreferences(); }
public FSequenceWindowToolbar(FSequenceEditorWindow window) { _window = window; _firstFrame = new GUIContent(FUtility.GetFluxTexture("FirstFrame.png"), "First Frame"); _previousFrame = new GUIContent(FUtility.GetFluxTexture("PreviousFrame.png"), "Previous Frame"); _nextFrame = new GUIContent(FUtility.GetFluxTexture("NextFrame.png"), "Next Frame"); _lastFrame = new GUIContent(FUtility.GetFluxTexture("LastFrame.png"), "Last Frame"); _playForward = new GUIContent(FUtility.GetFluxTexture("Play.png"), "Play"); _pause = new GUIContent(FUtility.GetFluxTexture("Pause.png"), "Pause"); _stop = new GUIContent(FUtility.GetFluxTexture("Stop.png"), "Stop"); _viewRangeLabel = new GUIContent("View Range"); _viewRangeDash = new GUIContent(" - "); }
public void ResizeEventsLeft(int delta) { int howMuchCanResize = int.MaxValue; // making them bigger? if (delta < 0) { for (int i = 0; i != _selectedEvents.Count; ++i) { int evtId = _selectedEvents[i].GetRuntimeObject().GetId(); int howMuchCanEvtResize = _selectedEvents[i]._evt.Start; if (evtId > 0) { howMuchCanEvtResize -= _selectedEvents[i]._evt.GetTrack().GetEvent(evtId - 1).End; } if (howMuchCanResize > howMuchCanEvtResize) { howMuchCanResize = howMuchCanEvtResize; } } delta = Mathf.Clamp(delta, -howMuchCanResize, 0); } else // making them smaller { for (int i = 0; i != _selectedEvents.Count; ++i) { int howMuchCanEvtResize = _selectedEvents[i]._evt.Length - _selectedEvents[i]._evt.GetMinLength(); if (howMuchCanResize > howMuchCanEvtResize) { howMuchCanResize = howMuchCanEvtResize; } } delta = Mathf.Clamp(delta, 0, howMuchCanResize); } for (int i = 0; i != _selectedEvents.Count; ++i) { FrameRange evtRange = _selectedEvents[i]._evt.FrameRange; evtRange.Start += delta; FUtility.Resize(_selectedEvents[i]._evt, evtRange); } }
public void Stop() { if (!object.Equals(_sequence, null)) { if (!_sequence.IsStopped) { _sequence.Stop(true); for (int i = 0; i != _timelineEditors.Count; ++i) { _timelineEditors[i].OnStop(); } } } _isPlaying = false; FUtility.RepaintGameView(); }
public override void Init(FObject obj, FEditor owner) { base.Init(obj, owner); Editors.Clear(); List <FTrack> tracks = Container.Tracks; for (int i = 0; i < tracks.Count; ++i) { FTrack track = tracks[i]; FTrackEditor trackEditor = SequenceEditor.GetEditor <FTrackEditor>(track); trackEditor.Init(track, this); Editors.Add(trackEditor); } _icon = new GUIContent(FUtility.GetFluxTexture("Plus.png")); }
public void SetCurrentFrame(int frame) { if (!_sequence.IsInit) { _sequence.Init(); } _sequence.SetCurrentFrameEditor(frame); frame = _sequence.GetCurrentFrame(); float time = frame * _sequence.InverseFrameRate; for (int i = 0; i != _timelineEditors.Count; ++i) { _timelineEditors[i].UpdateTracks(frame, time); } FUtility.RepaintGameView(); }
protected override void OnEnable() { base.OnEnable(); _audioEvt = (FVolumeAudioEvent)target; _source = serializedObject.FindProperty("_source"); _sources = FUtility.FindObjects <AudioSource>(); _sourceNames = new GUIContent[_sources.Length]; for (int i = 0; i < _sources.Length; i++) { _sourceNames[i] = new GUIContent(_sources[i].name); } if (_sources.Length > 0) { _source.objectReferenceValue = _sources[_selectedIndex]; } serializedObject.ApplyModifiedProperties(); }
public override void Init(FObject obj, FEditor owner) { base.Init(obj, owner); Editors.Clear(); List <FTimeline> timelines = Container.Timelines; for (int i = 0; i < timelines.Count; ++i) { FTimeline timeline = timelines[i]; FTimelineEditor timelineEditor = SequenceEditor.GetEditor <FTimelineEditor>(timeline); timelineEditor.Init(timeline, this); Editors.Add(timelineEditor); } _icon = new GUIContent(FUtility.GetFluxTexture("Folder.png")); // _contentOffset = new Vector2(8, HeaderHeight); }
public void Play(bool restart) { if (!_sequence.IsStopped && restart) { _sequence.Stop(); } int frame = _viewRange.Cull(_sequence.GetCurrentFrame()); _sequence.Play(frame); _timeStartedPlaying = EditorApplication.timeSinceStartup - (frame - _viewRange.Start) * _sequence.InverseFrameRate; SetCurrentFrame(frame); _isPlaying = true; FUtility.RepaintGameView(); }
public static void SetAnimator(FAnimationTrack animTrack) { if (animTrack.Owner.GetComponent <Animator>() == null) { Animator animator = animTrack.Owner.gameObject.AddComponent <Animator>(); Undo.RegisterCreatedObjectUndo(animator, string.Empty); } if (animTrack.AnimatorController == null) { var temp = FUtility.GetFluxAssets <UnityEditor.Animations.AnimatorController>("EditorAnimatorController.controller"); var animatorController = Instantiate(temp); animTrack.LayerId = 0; animTrack.LayerName = "Base Layer"; var layers = animatorController.layers; layers[animTrack.LayerId].name = animTrack.LayerName; layers[animTrack.LayerId].stateMachine.name = animTrack.LayerName; animatorController.layers = layers; animTrack.AnimatorController = animatorController; FAnimationTrackInspector.RebuildStateMachine(animTrack); } }
void OnEnable() { instance = this; wantsMouseMove = true; minSize = new Vector2(450, 300); _windowHeader = new FSequenceWindowHeader(this); _toolbar = new FSequenceWindowToolbar(this); _windowRect = new Rect(); FUtility.LoadPreferences(); EditorApplication.playmodeStateChanged += OnPlayModeChanged; EditorApplication.hierarchyWindowChanged += Refresh; Undo.undoRedoPerformed += OnUndo; Undo.postprocessModifications += PostProcessModifications; }
protected override void OnHeaderInput(Rect labelRect, Rect iconRect) { if (Event.current.type == EventType.MouseDown && Event.current.clickCount > 1 && labelRect.Contains(Event.current.mousePosition)) { Selection.activeTransform = Container.Owner; Event.current.Use(); } base.OnHeaderInput(labelRect, iconRect); if (Event.current.type == EventType.MouseDown && iconRect.Contains(Event.current.mousePosition)) { FSettings fSettings = FUtility.GetSettings(); FContainerSetting setting = fSettings.ContainerType.Find(c => c._type == Container.ConatinerType); if (setting == null) { ShowAddTrackMenu(); } else { ShowAddTrackMenuBaseOnType(setting); } } }
public override void OnEnable() { base.OnEnable(); if (target == null) { DestroyImmediate(this); return; } var sequenceTrack = (FSequenceTrack)target; _ownerSequence = serializedObject.FindProperty("_ownerSequence"); _sequences = new List <FSequence>(FUtility.FindObjects <FSequence>()); _sequences.Remove(sequenceTrack.Sequence); _sequences.Sort(delegate(FSequence x, FSequence y) { return(x.name.CompareTo(y.name)); }); _selectedSequenceIndex = _sequences.FindIndex((select) => select.name == _ownerSequence.objectReferenceValue.name); _sequenceNames = new GUIContent[_sequences.Count]; for (int i = 0; i != _sequences.Count; ++i) { _sequenceNames[i] = new GUIContent(_sequences[i].name); } }
public override void Render(Rect rect, float headerWidth) { Rect = rect; _headerWidth = headerWidth; Rect headerRect = rect; headerRect.width = headerWidth; Rect viewRect = rect; viewRect.xMax = rect.xMin + headerWidth; viewRect.xMin = viewRect.xMax - 16; viewRect.height = 16; if (Track.CanTogglePreview) { if (Event.current.type == EventType.MouseDown) { if (viewRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) // left click? { if (Event.current.shift) // turn all? { SequenceEditor.TurnOnAllPreviews(!Track.CanPreview); } else { OnTogglePreview(!Track.CanPreview); } FUtility.RepaintGameView(); Event.current.Use(); } } } } Rect trackHeaderRect = rect; trackHeaderRect.xMax = viewRect.xMax; //headerWidth; Color guiColor = GUI.color; bool selected = _isSelected; if (selected) { Color c = FGUI.GetSelectionColor(); c.a = GUI.color.a; GUI.color = c; GUI.DrawTexture(trackHeaderRect, EditorGUIUtility.whiteTexture); GUI.color = guiColor; } if (!Track.enabled) { Color c = guiColor; c.a = 0.5f; GUI.color = c; } Rect trackLabelRect = trackHeaderRect; trackLabelRect.xMin += 8; GUI.Label(trackLabelRect, new GUIContent(Track.name), FGUI.GetTrackHeaderStyle()); rect.xMin = trackHeaderRect.xMax; if (rect.Contains(Event.current.mousePosition)) { SequenceEditor.SetMouseHover(Event.current.mousePosition.x - rect.xMin, this); } FrameRange validKeyframeRange = new FrameRange(0, SequenceEditor.Sequence.Length); for (int i = 0; i != _eventEditors.Count; ++i) { if (i == 0) { validKeyframeRange.Start = 0; } else { validKeyframeRange.Start = _eventEditors[i - 1].Evt.End; } if (i == _eventEditors.Count - 1) { validKeyframeRange.End = SequenceEditor.Sequence.Length; } else { validKeyframeRange.End = _eventEditors[i + 1].Evt.Start; } _eventEditors[i].Render(rect, SequenceEditor.ViewRange, SequenceEditor.PixelsPerFrame, validKeyframeRange); } switch (Event.current.type) { case EventType.ContextClick: if (trackHeaderRect.Contains(Event.current.mousePosition)) { OnHeaderContextClick(); } else if (Rect.Contains(Event.current.mousePosition)) { OnBodyContextClick(); } break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && trackHeaderRect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) // selecting { if (Event.current.control) { if (IsSelected) { SequenceEditor.Deselect(this); } else { SequenceEditor.Select(this); } } else if (Event.current.shift) { SequenceEditor.Select(this); } else { SequenceEditor.SelectExclusive(this); } Event.current.Use(); } } break; case EventType.MouseUp: // if( EditorGUIUtility.hotControl == GuiId ) // { // EditorGUIUtility.hotControl = 0; // _offsetAnim.value = _offsetAnim.target = Vector2.zero; // //// if( TimelineEditor ) TimelineEditor.StopTrackDrag(); // // SequenceEditor.Repaint(); // Event.current.Use(); // } break; case EventType.MouseDrag: // if( EditorGUIUtility.hotControl == GuiId ) // { // SequenceEditor.Repaint(); // Event.current.Use(); // } break; } if (Track.CanTogglePreview) { GUI.color = GetPreviewIconColor(); //FGUI.GetTextColor(); if (!Track.CanPreview) { Color c = GUI.color; c.a = 0.3f; GUI.color = c; } GUI.DrawTexture(viewRect, _previewIcon); GUI.color = Color.white; } Handles.color = FGUI.GetLineColor(); Handles.DrawLine(Rect.min, Rect.min + new Vector2(Rect.width, 0)); Handles.DrawLine(Rect.max, Rect.max - new Vector2(Rect.width, 0)); GUI.color = guiColor; }
public void OnGUI() { if (_timelineEditors == null) { return; } if (_timelineEditors.Count == 0) { if (_renderingOnEditorWindow) { _renderingOnEditorWindow.ShowNotification(new GUIContent("Drag GameObjects Here")); } } _pixelsPerFrame = (_sequenceRect.width - _timelineHeaderWidth) / _viewRange.Length; if (_timelineEditorIds.Length != _timelineEditors.Count) { _timelineEditorIds = new int[_timelineEditors.Count]; _timelineEditorHeights = new float[_timelineEditors.Count]; } int timelineHeaderResizerId = EditorGUIUtility.GetControlID(FocusType.Passive); float sequenceViewHeight = 0; for (int i = 0; i != _timelineEditors.Count; ++i) { _timelineEditorIds[i] = EditorGUIUtility.GetControlID(FocusType.Passive); _timelineEditorHeights[i] = _timelineEditors[i].GetHeight(); sequenceViewHeight += _timelineEditorHeights[i]; _timelineEditors[i].ReserveTrackGuiIds(); } _scrollPos.y = GUI.VerticalScrollbar(_verticalScrollerRect, _scrollPos.y, Mathf.Min(_sequenceRect.height, sequenceViewHeight), 0, sequenceViewHeight); Rect scrolledViewRect = _viewRect; // scrolledViewRect.yMin -= _scrollPos.y; GUI.BeginGroup(scrolledViewRect); Rect timelineRect = _sequenceRect; timelineRect.y = -_scrollPos.y; timelineRect.height = 0; Rect timelineDraggedRect = new Rect(); // Debug.Log( "sequence: " + _sequenceRect + " scrubber: " + _timeScrubberRect + " width: " + _timelineHeaderWidth ); Handles.color = FGUI.GetLineColor(); for (int i = 0; i != _timelineEditors.Count; ++i) { timelineRect.yMin = timelineRect.yMax; timelineRect.height = _timelineEditors[i].GetHeight(); if (_timelineDragged != null) { if (_timelineDragged == _timelineEditors[i]) { timelineDraggedRect = timelineRect; continue; } else if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()]) { if (i < _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y < timelineRect.yMax) { _timelineEditors[i].SetOffset(new Vector2(0, _timelineDragged.GetHeight())); } else if (i > _timelineDragged.GetRuntimeObject().GetId() && Event.current.mousePosition.y > timelineRect.yMin) { _timelineEditors[i].SetOffset(new Vector2(0, -_timelineDragged.GetHeight())); } else { _timelineEditors[i].SetOffset(Vector2.zero); } } } _timelineEditors[i].Render(_timelineEditorIds[i], timelineRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame); } if (_timelineDragged != null) { if (EditorGUIUtility.hotControl == _timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()]) { timelineDraggedRect.y = Event.current.mousePosition.y; } // timelineRect.yMin = Event.current.mousePosition.y; // timelineRect.height = _timelineDragged.GetHeight(); _timelineDragged.Render(_timelineEditorIds[_timelineDragged.GetRuntimeObject().GetId()], timelineDraggedRect, _timelineHeaderWidth, _viewRange, _pixelsPerFrame); } switch (Event.current.type) { case EventType.MouseDown: // bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt); // // if( middleClick ) // middle button if (Event.current.button == 0) { StartDragSelecting(Event.current.mousePosition); Event.current.Use(); } break; case EventType.MouseUp: if (_isDragSelecting) { StopDragSelecting(Event.current.mousePosition); Event.current.Use(); } break; case EventType.Ignore: if (_isDragSelecting) { StopDragSelecting(Event.current.mousePosition); } break; case EventType.Repaint: if (_isDragSelecting) { OnDragSelecting(Event.current.mousePosition); } break; } GUI.EndGroup(); if (_viewRange.End > _sequence.Length) { _viewRange.Start = 0; _viewRange.End = _sequence.Length; } int newT = FGUI.TimeScrubber(_timeScrubberRect, _sequence.GetCurrentFrame(), _sequence.FrameRate, _viewRange); if (newT != _sequence.GetCurrentFrame()) { // _sequence.SetCurrentFrameEditor( newT ); SetCurrentFrame(newT); if (Application.isPlaying) { Play(false); Pause(); } // Repaint(); // SceneView.RepaintAll(); // UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); // FUtility.RepaintGameView(); } _viewRange = FGUI.ViewRangeBar(_viewRangeRect, _viewRange, _sequence.Length); if (_timelineHeaderResizerRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.AddCursorRect(_timelineHeaderResizerRect, MouseCursor.ResizeHorizontal); } switch (Event.current.type) { case EventType.MouseDown: bool leftClick = Event.current.button == 0 && !Event.current.alt; // bool middleClick = Event.current.button == 2 || (Event.current.button == 0 && Event.current.alt); if (leftClick) // left button { if (EditorGUIUtility.hotControl == 0 && _timelineHeaderResizerRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.hotControl = timelineHeaderResizerId; Event.current.Use(); } else if (_rect.Contains(Event.current.mousePosition)) { DeselectAll(); Event.current.Use(); } } // else if( middleClick ) // middle button // { // StartDragSelecting( Event.current.mousePosition ); // Event.current.Use(); // } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == timelineHeaderResizerId) { _timelineHeaderWidth = (int)Mathf.Max(MINIMUM_HEADER_WIDTH, _timelineHeaderWidth + Event.current.delta.x); RebuildLayout(_rect); EditorWindow.GetWindow <FSequenceEditorWindow>().Repaint(); Event.current.Use(); } if (_isDragSelecting) { Repaint(); } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == timelineHeaderResizerId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } // if( _isDragSelecting ) // { // StopDragSelecting( Event.current.mousePosition ); // Event.current.Use(); // } break; case EventType.Repaint: Rect dragArea = _timelineHeaderResizerRect; dragArea.xMax -= 10; dragArea.xMin = dragArea.xMax - 16; GUIStyle dragStyle = FUtility.GetFluxSkin().GetStyle("HorizontalPanelSeparatorHandle"); dragStyle.Draw(dragArea, GUIContent.none, 0); // GUI.DrawTexture( dragArea, EditorGUIUtility.whiteTexture ); Handles.color = FGUI.GetLineColor(); // new Color(0.8f, 0.8f, 0.8f, 0.2f); Handles.DrawLine(new Vector3(_viewRect.xMin - 16, _sequenceRect.yMax, 0), new Vector3(_viewRect.xMax - RIGHT_BORDER, _sequenceRect.yMax, 0)); // Handles.color = Color.black; break; case EventType.ScrollWheel: if (_viewRect.Contains(Event.current.mousePosition)) { _scrollPos.y += Event.current.delta.y * SCROLL_WHEEL_SPEED; Event.current.Use(); } break; } #if FLUX_TRIAL GUIStyle watermarkLabel = new GUIStyle(GUI.skin.label); watermarkLabel.fontSize = 24; GUIContent watermark = new GUIContent("..::FLUX TRIAL::.."); Vector2 watermarkSize = watermarkLabel.CalcSize(watermark); Rect watermarkRect = new Rect(_rect.width * 0.5f - watermarkSize.x * 0.5f, _rect.height * 0.5f - watermarkSize.y * 0.5f, watermarkSize.x, watermarkSize.y); GUI.color = new Color(1f, 1f, 1f, 0.4f); GUI.Label(watermarkRect, watermark, watermarkLabel); #endif }
protected override void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange) { if (_animEvtSO == null) { _animEvtSO = new SerializedObject(AnimEvt); _blendLength = _animEvtSO.FindProperty("_blendLength"); _startOffset = _animEvtSO.FindProperty("_startOffset"); } UpdateEventFromController(); _animEvtSO.Update(); FAnimationTrackEditor animTrackEditor = (FAnimationTrackEditor)TrackEditor; Rect transitionOffsetRect = _eventRect; int startOffsetHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int transitionHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); bool isBlending = AnimEvt.IsBlending(); bool isAnimEditable = Flux.FUtility.IsAnimationEditable(AnimEvt._animationClip); if (isBlending) { transitionOffsetRect.xMin = Rect.xMin + SequenceEditor.GetXForFrame(AnimEvt.Start + AnimEvt._blendLength) - 3; transitionOffsetRect.width = 6; transitionOffsetRect.yMin = transitionOffsetRect.yMax - 8; } switch (Event.current.type) { case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && Event.current.alt && !isAnimEditable) { if (isBlending && transitionOffsetRect.Contains(Event.current.mousePosition)) { EditorGUIUtility.hotControl = transitionHandleId; AnimatorWindowProxy.OpenAnimatorWindowWithAnimatorController((AnimatorController)AnimTrack.AnimatorController); if (Selection.activeObject != _transitionToState) { Selection.activeObject = _transitionToState; } Event.current.Use(); } else if (_eventRect.Contains(Event.current.mousePosition)) { _mouseDown = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - AnimEvt.Start; EditorGUIUtility.hotControl = startOffsetHandleId; Event.current.Use(); } } break; case EventType.Ignore: case EventType.MouseUp: if (EditorGUIUtility.hotControl == transitionHandleId || EditorGUIUtility.hotControl == startOffsetHandleId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == transitionHandleId) { int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length); if (_blendLength.intValue != mouseDragPos) { _blendLength.intValue = mouseDragPos; FPlayAnimationEvent prevAnimEvt = (FPlayAnimationEvent)animTrackEditor.Track.GetEvent(AnimEvt.GetId() - 1); if (_transitionDuration != null) { _transitionDuration.floatValue = (_blendLength.intValue / prevAnimEvt._animationClip.frameRate) / prevAnimEvt._animationClip.length; } Undo.RecordObject(this, "Animation Blending"); } Event.current.Use(); } else if (EditorGUIUtility.hotControl == startOffsetHandleId) { int mouseDragPos = Mathf.Clamp(SequenceEditor.GetFrameForX(Event.current.mousePosition.x - Rect.x) - AnimEvt.Start, 0, AnimEvt.Length); int delta = _mouseDown - mouseDragPos; _mouseDown = mouseDragPos; _startOffset.intValue = Mathf.Clamp(_startOffset.intValue + delta, 0, AnimEvt._animationClip.isLooping ? AnimEvt.Length : Mathf.RoundToInt(AnimEvt._animationClip.length * AnimEvt._animationClip.frameRate) - AnimEvt.Length); if (_transitionOffset != null) { _transitionOffset.floatValue = (_startOffset.intValue / AnimEvt._animationClip.frameRate) / AnimEvt._animationClip.length; } Undo.RecordObject(this, "Animation Offset"); Event.current.Use(); } break; } _animEvtSO.ApplyModifiedProperties(); if (_transitionSO != null) { _transitionSO.ApplyModifiedProperties(); } switch (Event.current.type) { case EventType.DragUpdated: if (_eventRect.Contains(Event.current.mousePosition)) { int numAnimationsDragged = FAnimationEventInspector.NumAnimationsDragAndDrop(Evt.Sequence.FrameRate); DragAndDrop.visualMode = numAnimationsDragged > 0 ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; Event.current.Use(); } break; case EventType.DragPerform: if (_eventRect.Contains(Event.current.mousePosition)) { AnimationClip animationClipDragged = FAnimationEventInspector.GetAnimationClipDragAndDrop(Evt.Sequence.FrameRate); if (animationClipDragged) { int animFrameLength = Mathf.RoundToInt(animationClipDragged.length * animationClipDragged.frameRate); FAnimationEventInspector.SetAnimationClip(AnimEvt, animationClipDragged); FrameRange maxRange = AnimEvt.GetMaxFrameRange(); SequenceEditor.MoveEvent(AnimEvt, new FrameRange(AnimEvt.Start, Mathf.Min(AnimEvt.Start + animFrameLength, maxRange.End))); DragAndDrop.AcceptDrag(); Event.current.Use(); } else { Event.current.Use(); } } break; } // FrameRange currentRange = Evt.FrameRange; base.RenderEvent(viewRange, validKeyframeRange); // if( isAnimEditable && currentRange.Length != Evt.FrameRange.Length ) // { // FAnimationEventInspector.ScaleAnimationClip( AnimEvt._animationClip, Evt.FrameRange ); // } if (Event.current.type == EventType.Repaint) { if (isBlending && !isAnimEditable && viewRange.Contains(AnimEvt.Start + AnimEvt._blendLength)) { GUISkin skin = FUtility.GetFluxSkin(); GUIStyle transitionOffsetStyle = skin.GetStyle("BlendOffset"); Texture2D t = FUtility.GetFluxTexture("EventBlend.png"); Rect r = new Rect(_eventRect.xMin, _eventRect.yMin + 1, transitionOffsetRect.center.x - _eventRect.xMin, _eventRect.height - 2); Color guiColor = GUI.color; Color c = new Color(1f, 1f, 1f, 0.3f); c.a *= guiColor.a; GUI.color = c; GUI.DrawTexture(r, t); if (Event.current.alt) { GUI.color = Color.white; } transitionOffsetStyle.Draw(transitionOffsetRect, false, false, false, false); GUI.color = guiColor; // Debug.Log ( transitionOffsetRect ); } // GUI.color = Color.red; if (EditorGUIUtility.hotControl == transitionHandleId) { Rect transitionOffsetTextRect = transitionOffsetRect; transitionOffsetTextRect.y -= 16; transitionOffsetTextRect.height = 20; transitionOffsetTextRect.width += 50; GUI.Label(transitionOffsetTextRect, AnimEvt._blendLength.ToString(), EditorStyles.label); } if (EditorGUIUtility.hotControl == startOffsetHandleId) { Rect startOffsetTextRect = _eventRect; GUI.Label(startOffsetTextRect, AnimEvt._startOffset.ToString(), EditorStyles.label); } } }
public void RenderTransformCurves(int samplesPerSecond) { if (_transformCurves == null || _transformCurves.clip == null) { CreateTransformCurves(); } else { _transformCurves.RefreshCurves(); } float totalTime = AnimEvt.LengthTime; float timePerSample = totalTime / samplesPerSecond; int numSamples = Mathf.RoundToInt(totalTime / timePerSample) + 1; Vector3[] pts = new Vector3[numSamples]; float t = 0; for (int i = 0; i < numSamples; ++i) { pts[i] = _transformCurves.GetWorldPosition(t); t += timePerSample; } Handles.DrawPolyLine(pts); FAnimationTrackEditor animTrackEditor = (FAnimationTrackEditor)TrackEditor; // if( _transformCurves.clip.name.Contains("1") ) // Debug.Log( _transformCurves.xRot.keys[0].tangentMode + " " + _transformCurves.yRot[0].tangentMode + " " + _transformCurves.zRot[0].tangentMode + " " + _transformCurves.wRot[0].tangentMode ); if (animTrackEditor.ShowKeyframes || animTrackEditor.ShowKeyframeTimes) { int animFramerate = Mathf.RoundToInt(_transformCurves.clip.frameRate); Keyframe[] keyframes = _transformCurves.GetPositionKeyframes(); for (int i = 0; i != keyframes.Length; ++i) { Keyframe keyframe = keyframes[i]; Vector3 pos = _transformCurves.GetPosition(keyframe.time); Quaternion rot = _transformCurves.GetRotation(keyframe.time); Quaternion toolRot = rot; bool isGlobalRotation = Tools.pivotRotation == PivotRotation.Global; if (isGlobalRotation) { toolRot = _globalRotation; //Quaternion.identity; } // Handles.color = Color.gray; // Vector3 newPos = Handles.FreeMoveHandle(pos, rot, 1, Vector3.one*0.2f, Handles.SphereCap);//Handles.PositionHandle( pos, rot ); if (animTrackEditor.ShowKeyframes) { if (Tools.current == Tool.Move) { Vector3 newPos = Handles.DoPositionHandle(pos, toolRot); //Handles.PositionHandle( pos, rot ); if (newPos != pos) { Undo.RecordObject(_transformCurves.clip, "Change Keyframe"); _transformCurves.SetPosition(newPos, keyframe.time); } } else if (Tools.current == Tool.Rotate) { Quaternion newRot = Handles.DoRotationHandle(toolRot, pos); if (newRot != toolRot) { Undo.RecordObject(_transformCurves.clip, "Change Keyframe"); _transformCurves.SetRotation(isGlobalRotation ? (newRot * Quaternion.Inverse(toolRot)) * rot : newRot, keyframe.time); if (isGlobalRotation) { _globalRotation = newRot; } } } } if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.Ignore) { _globalRotation = Quaternion.identity; } if (animTrackEditor.ShowKeyframeTimes) { int frame = Mathf.RoundToInt(keyframe.time * animFramerate); Handles.Label(pos + new Vector3(0, .25f, 0), FUtility.GetTime(AnimEvt.Start + frame, animFramerate), EditorStyles.toolbarButton); } // Handles.BeginGUI(); // Vector3 screenPos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint( pos ); // GUI.Label( new Rect( screenPos.x-10, SceneView.currentDrawingSceneView.position.height-screenPos.y-50, 20, 20 ), keyframe.time.ToString() ); // Handles.EndGUI(); } } }
protected override void OnEnable() { base.OnEnable(); _previewIcon = (Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "View.png", typeof(Texture2D)); }
public void OnGUI() { FSequence sequence = _sequenceWindow.GetSequenceEditor().GetSequence(); if (_selectedSequenceIndex < 0 && sequence != null) { for (int i = 0; i != _sequences.Length; ++i) { if (_sequences[i] == sequence) { _selectedSequenceIndex = i; break; } } } GUI.contentColor = FGUI.GetTextColor(); if (Event.current.type == EventType.MouseDown && Event.current.alt && _sequencePopupRect.Contains(Event.current.mousePosition)) { Selection.activeObject = sequence; Event.current.Use(); } EditorGUI.BeginChangeCheck(); EditorGUI.PrefixLabel(_sequenceLabelRect, _sequenceLabel); int newSequenceIndex = EditorGUI.Popup(_sequencePopupRect, _selectedSequenceIndex, _sequenceNames); if (EditorGUI.EndChangeCheck()) { _selectedSequenceIndex = newSequenceIndex; _sequenceWindow.GetSequenceEditor().OpenSequence(_sequences[_selectedSequenceIndex]); _sequenceWindow.RemoveNotification(); EditorGUIUtility.keyboardControl = 0; // deselect it EditorGUIUtility.ExitGUI(); } if (GUI.Button(_sequenceAddButtonRect, new GUIContent((Texture2D)AssetDatabase.LoadAssetAtPath(FUtility.GetFluxSkinPath() + "Plus.png", typeof(Texture2D)), "Create New Sequence.."), EditorStyles.label)) { FSequence newSequence = FSequenceEditorWindow.CreateSequence(); _sequenceWindow.GetSequenceEditor().OpenSequence(newSequence); EditorGUIUtility.ExitGUI(); } if (sequence == null) { return; } if (_sequenceSO == null || _sequenceSO.targetObject != sequence) { _sequenceSO = new SerializedObject(sequence); _sequenceUpdateMode = _sequenceSO.FindProperty("_updateMode"); _sequenceLength = _sequenceSO.FindProperty("_length"); } _sequenceSO.Update(); if (_showUpdadeMode) { EditorGUI.PrefixLabel(_updateModeLabelRect, _updateModeLabel); EditorGUI.PropertyField(_updateModeFieldRect, _sequenceUpdateMode, GUIContent.none); } if (_showFramerate) { EditorGUI.PrefixLabel(_framerateLabelRect, _framerateLabel); EditorGUI.BeginChangeCheck(); int newFrameRate = FGUI.FrameRatePopup(_framerateFieldRect, sequence.FrameRate); if (EditorGUI.EndChangeCheck()) { if (newFrameRate == -1) { FChangeFrameRateWindow.Show(new Vector2(_framerateLabelRect.xMin, _framerateLabelRect.yMax), sequence, FSequenceInspector.Rescale); } else { FSequenceInspector.Rescale(sequence, newFrameRate, true); } } } if (_showLength) { EditorGUI.PrefixLabel(_lengthLabelRect, _lengthLabel); _sequenceLength.intValue = EditorGUI.IntField(_lengthFieldRect, _sequenceLength.intValue, _numberFieldStyle); } _sequenceSO.ApplyModifiedProperties(); }
public virtual GUIStyle GetEventStyle() { return(FUtility.GetEventStyle()); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(_randomSeed, _randomSeedUI); if (GUILayout.Button(new GUIContent("R", "随机获得一个种子"), GUILayout.Width(25))) { _randomSeed.intValue = Random.Range(0, int.MaxValue); } EditorGUILayout.EndHorizontal(); if (_randomSeed.intValue == 0) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("A random seed of 0 means that it always randomizes the particle system, which breaks backwards play of particle systems", MessageType.Warning); if (GUILayout.Button("Fix", GUILayout.Width(40), GUILayout.Height(40))) { _randomSeed.intValue = Random.Range(0, int.MaxValue); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.PropertyField(_particleSystem, _particleSystemUI); serializedObject.ApplyModifiedProperties(); ParticleSystem particleSystem = _particleSystem.objectReferenceValue as ParticleSystem; if (particleSystem == null) { EditorGUILayout.HelpBox("粒子事件中未添加粒子对象", MessageType.Warning); return; } if (_playParticleEvent.LengthTime > particleSystem.main.duration || _playParticleEvent.LengthTime > particleSystem.main.startLifetime.constant) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("粒子的持续时间/开始时间小于事件长度,这将与游戏运行时结果不一致", MessageType.Warning); if (GUILayout.Button("Fix", GUILayout.Width(40), GUILayout.Height(40))) { int selectedOption = EditorUtility.DisplayDialogComplex("修正粒子事件?", "不幸的是,Unity的粒子系统并不完全支持向后播放." + "你想怎么纠正这个?" + "\n - 增加粒子持续时间:使粒子持续时间与事件的长度相同" + "\n - 收缩事件:将事件大小调整为粒子系统的长度", "增加粒子持续时间", "取消", "收缩事件"); switch (selectedOption) { case 0: // Increase duration SerializedObject particleSystemSO = new SerializedObject(particleSystem); particleSystemSO.FindProperty("lengthInSec").floatValue = _playParticleEvent.LengthTime; particleSystemSO.FindProperty("InitialModule.startLifetime.scalar").floatValue = _playParticleEvent.LengthTime; particleSystemSO.ApplyModifiedProperties(); break; case 1: // Cancel break; case 2: // Shrink event FUtility.Rescale(_playParticleEvent, new FrameRange(_playParticleEvent.FrameRange.Start, Mathf.RoundToInt(Mathf.Min(particleSystem.main.duration, particleSystem.main.startLifetime.constant) * _playParticleEvent.Sequence.FrameRate))); break; } } EditorGUILayout.EndHorizontal(); } }