public override void OnInspectorGUI() { bool rebuildTrack = false; base.OnInspectorGUI(); serializedObject.Update(); if (_animationClip.objectReferenceValue == null) { EditorGUILayout.HelpBox("There's no Animation Clip", MessageType.Warning); Rect helpBoxRect = GUILayoutUtility.GetLastRect(); float yCenter = helpBoxRect.center.y; helpBoxRect.xMax -= 3; helpBoxRect.xMin = helpBoxRect.xMax - 50; helpBoxRect.yMin = yCenter - 12.5f; helpBoxRect.height = 25f; FAnimationTrack animTrack = (FAnimationTrack)_animEvent.Track; if (animTrack.AnimatorController == null || animTrack.LayerId == -1) { GUI.enabled = false; } if (GUI.Button(helpBoxRect, "Create")) { CreateAnimationClip(_animEvent); } GUI.enabled = true; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_animationClip); Rect animationClipRect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.DragUpdated && animationClipRect.Contains(Event.current.mousePosition)) { int numAnimations = NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate); if (numAnimations > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } else if (Event.current.type == EventType.DragPerform && animationClipRect.Contains(Event.current.mousePosition)) { if (NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate) > 0) { DragAndDrop.AcceptDrag(); AnimationClip clip = GetAnimationClipDragAndDrop(_animEvent.Sequence.FrameRate); if (clip != null) { _animationClip.objectReferenceValue = clip; } } } if (EditorGUI.EndChangeCheck()) { AnimationClip clip = (AnimationClip)_animationClip.objectReferenceValue; if (clip) { if (clip.frameRate != _animEvent.Track.Timeline.Sequence.FrameRate) { Debug.LogError(string.Format("Can't add animation, it has a different frame rate from the sequence ({0} vs {1})", clip.frameRate, _animEvent.Track.Timeline.Sequence.FrameRate)); _animationClip.objectReferenceValue = null; } else { SerializedProperty frameRangeEnd = _frameRange.FindPropertyRelative("_end"); FrameRange maxFrameRange = _animEvent.GetMaxFrameRange(); frameRangeEnd.intValue = Mathf.Min(_animEvent.FrameRange.Start + Mathf.RoundToInt(clip.length * clip.frameRate), maxFrameRange.End); } rebuildTrack = true; } else { CheckDeleteAnimation(_animEvent); } } bool isAnimationEditable = Flux.FUtility.IsAnimationEditable(_animEvent._animationClip); if (isAnimationEditable) { EditorGUILayout.PropertyField(_controlsAnimation); } else { if (_controlsAnimation.boolValue) { _controlsAnimation.boolValue = false; } } if (!_controlsAnimation.boolValue) { if (_animEvent.IsBlending()) { float offset = _startOffset.intValue / _animEvent._animationClip.frameRate; float blendFinish = offset + (_blendLength.intValue / _animEvent._animationClip.frameRate); EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(EditorGUIUtility.labelWidth - 5)); // hack to get around some layout issue with imgui _showBlendAndOffsetContent = EditorGUILayout.Foldout(_showBlendAndOffsetContent, new GUIContent("Offset+Blend")); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(ref offset, ref blendFinish, 0, _animEvent.GetMaxStartOffset() / _animEvent._animationClip.frameRate + _animEvent.LengthTime); if (EditorGUI.EndChangeCheck()) { _startOffset.intValue = Mathf.Clamp(Mathf.RoundToInt(offset * _animEvent.Sequence.FrameRate), 0, _animEvent.GetMaxStartOffset()); _blendLength.intValue = Mathf.Clamp(Mathf.RoundToInt((blendFinish - offset) * _animEvent.Sequence.FrameRate), 0, _animEvent.Length); rebuildTrack = true; } EditorGUILayout.EndHorizontal(); if (_showBlendAndOffsetContent) { EditorGUI.BeginChangeCheck(); ++EditorGUI.indentLevel; if (!isAnimationEditable) { EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset()); } // if( _animEvent.IsBlending() ) { EditorGUILayout.IntSlider(_blendLength, 0, _animEvent.Length); } --EditorGUI.indentLevel; if (EditorGUI.EndChangeCheck()) { rebuildTrack = true; } } } else { EditorGUI.BeginChangeCheck(); EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset()); if (EditorGUI.EndChangeCheck()) { rebuildTrack = true; } } } serializedObject.ApplyModifiedProperties(); if (rebuildTrack) { FAnimationTrackInspector.RebuildStateMachine((FAnimationTrack)_animEvent.Track); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); if (_animationClip.objectReferenceValue == null) { EditorGUILayout.HelpBox("There's no Animation Clip", MessageType.Warning); Rect helpBoxRect = GUILayoutUtility.GetLastRect(); float yCenter = helpBoxRect.center.y; helpBoxRect.xMax -= 3; helpBoxRect.xMin = helpBoxRect.xMax - 50; helpBoxRect.yMin = yCenter - 12.5f; helpBoxRect.height = 25f; if (GUI.Button(helpBoxRect, "Create")) { CreateAnimationClip(_animEvent); } } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_animationClip); Rect animationClipRect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.DragUpdated && animationClipRect.Contains(Event.current.mousePosition)) { int numAnimations = NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate); if (numAnimations > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } else if (Event.current.type == EventType.DragPerform && animationClipRect.Contains(Event.current.mousePosition)) { if (NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate) > 0) { DragAndDrop.AcceptDrag(); AnimationClip clip = GetAnimationClipDragAndDrop(_animEvent.Sequence.FrameRate); if (clip != null) { _animationClip.objectReferenceValue = clip; } } } if (EditorGUI.EndChangeCheck()) { AnimationClip clip = (AnimationClip)_animationClip.objectReferenceValue; if (clip) { if (clip.frameRate != _animEvent.GetTrack().GetTimeline().Sequence.FrameRate) { Debug.LogError(string.Format("Can't add animation, it has a different frame rate from the sequence ({0} vs {1})", clip.frameRate, _animEvent.GetTrack().GetTimeline().Sequence.FrameRate)); _animationClip.objectReferenceValue = null; } else { SerializedProperty frameRangeEnd = _frameRange.FindPropertyRelative("_end"); FrameRange maxFrameRange = _animEvent.GetMaxFrameRange(); frameRangeEnd.intValue = Mathf.Min(_animEvent.FrameRange.Start + Mathf.RoundToInt(clip.length * clip.frameRate), maxFrameRange.End); } } } if (!_animEvent.IsAnimationEditable()) { EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset()); } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { bool rebuildTrack = false; base.OnInspectorGUI(); serializedObject.Update(); if (_animationClip.objectReferenceValue == null) { EditorGUILayout.HelpBox("无动画剪辑Clip", MessageType.Warning); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_animationClip, _animationClipUI); Rect animationClipRect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.DragUpdated && animationClipRect.Contains(Event.current.mousePosition)) { int numAnimations = NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate); if (numAnimations > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } else if (Event.current.type == EventType.DragPerform && animationClipRect.Contains(Event.current.mousePosition)) { if (NumAnimationsDragAndDrop(_animEvent.Sequence.FrameRate) > 0) { DragAndDrop.AcceptDrag(); AnimationClip clip = GetAnimationClipDragAndDrop(_animEvent.Sequence.FrameRate); if (clip != null) { _animationClip.objectReferenceValue = clip; } } } if (EditorGUI.EndChangeCheck()) { AnimationClip clip = (AnimationClip)_animationClip.objectReferenceValue; if (clip) { if (clip.frameRate != _animEvent.Track.Container.Sequence.FrameRate) { Debug.LogError(string.Format("Can't add animation, it has a different frame rate from the sequence ({0} vs {1})", clip.frameRate, _animEvent.Track.Container.Sequence.FrameRate)); _animationClip.objectReferenceValue = null; } else { SerializedProperty frameRangeEnd = _frameRange.FindPropertyRelative("_end"); FrameRange maxFrameRange = _animEvent.GetMaxFrameRange(); frameRangeEnd.intValue = Mathf.Min(_animEvent.FrameRange.Start + Mathf.RoundToInt(clip.length * clip.frameRate), maxFrameRange.End); } rebuildTrack = true; } else { CheckDeleteAnimation(_animEvent); } } if (_animEvent.IsBlending()) { int id = _animEvent.GetId(); FPlayAnimationEvent preAnimEvt = _animEvent.Track.Events[id - 1] as FPlayAnimationEvent; if (id > 0) { EditorGUI.BeginChangeCheck(); EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset(), _startOffsetUI); EditorGUILayout.IntSlider(_blendLength, 0, preAnimEvt.Length > _animEvent.Length ? _animEvent.Length : preAnimEvt.Length, _blendLengthUI); if (EditorGUI.EndChangeCheck()) { rebuildTrack = true; } } } else { EditorGUI.BeginChangeCheck(); EditorGUILayout.IntSlider(_startOffset, 0, _animEvent.GetMaxStartOffset(), _startOffsetUI); if (EditorGUI.EndChangeCheck()) { rebuildTrack = true; } } serializedObject.ApplyModifiedProperties(); if (rebuildTrack) { FAnimationTrackInspector.RebuildStateMachine((FAnimationTrack)_animEvent.Track); } }