private void OnGUI() { RightMenuGUI(); MoveViewGUI(); MorphEditorTool.SetGUIEnabled(!_isPreview); MorphEditorTool.SetGUIBackgroundColor(_isRecord ? Color.red : Color.white); TitleGUI(); MorphEditorTool.SetGUIBackgroundColor(Color.white); KeyframeGUI(); GUILayout.FlexibleSpace(); ClipsGUI(); ClipPropertyGUI(); KeyframePropertyGUI(); }
private void ClipsGUI() { string currentStyle = ""; string otherStyle = ""; for (int i = 0; i < _morphAnimator.Clips.Count; i++) { if (_currentClip != _morphAnimator.Clips[i]) { MorphAnimationClip clip = _morphAnimator.Clips[i]; if (!_isPreview) { MorphEditorTool.SetGUIEnabled(clip.Valid); } Rect rect = new Rect(clip.Anchor, new Vector2(_clipSizeWidth, _clipSizeHeight)); otherStyle = ((_morphAnimator.DefaultClipIndex == i) ? "flow node 5" : "flow node 0"); if (GUI.Button(rect, clip.Name, otherStyle)) { SelectClip(clip); currentStyle = otherStyle + " on"; } } else { currentStyle = ((_morphAnimator.DefaultClipIndex == i) ? "flow node 5 on" : "flow node 0 on"); } } if (_currentClip != null) { if (!_isPreview) { MorphEditorTool.SetGUIEnabled(_currentClip.Valid); } Rect rect = new Rect(_currentClip.Anchor, new Vector2(_clipSizeWidth, _clipSizeHeight)); if (GUI.RepeatButton(rect, _currentClip.Name, currentStyle)) { _currentClip.Anchor = Event.current.mousePosition - new Vector2(_clipSizeWidth / 2, _clipSizeHeight / 2); Repaint(); } } if (!_isPreview) { MorphEditorTool.SetGUIEnabled(true); } for (int i = 0; i < _morphAnimator.Clips.Count; i++) { if (_morphAnimator.Clips[i].TransitionClip != -1) { MorphAnimationClip clip = _morphAnimator.Clips[i]; Vector2 clipVec = new Vector2(clip.Anchor.x + _clipSizeWidth, clip.Anchor.y + _clipSizeHeight / 2); MorphAnimationClip transitionClip = _morphAnimator.Clips[clip.TransitionClip]; Vector2 transitionVec = new Vector2(transitionClip.Anchor.x, transitionClip.Anchor.y + _clipSizeHeight / 2); MorphHandles.DrawTransition(clipVec, transitionVec); } } }
private void TitleGUI() { GUILayout.BeginHorizontal("Toolbar"); if (GUILayout.Button(_skinnedMeshRenderer.transform.name, "Toolbarbutton", GUILayout.Width(100))) { Selection.activeGameObject = _skinnedMeshRenderer.gameObject; } if (GUILayout.Button(MorphStyle.IconGUIContent("Animation.Record"), "Toolbarbutton")) { _isRecord = !_isRecord; } if (GUILayout.Button(MorphStyle.IconGUIContent("Animation.PrevKey"), "Toolbarbutton")) { if (_currentKeyframe != null) { int index = _currentClip.Keyframes.IndexOf(_currentKeyframe); index -= 1; if (index < 0) { index = _currentClip.Keyframes.Count - 1; } SelectKeyframe(_currentClip.Keyframes[index]); } } MorphEditorTool.SetGUIEnabled(true); if (GUILayout.Toggle(_isPreview, MorphStyle.IconGUIContent("Animation.Play"), "Toolbarbutton") != _isPreview) { _isPreview = !_isPreview; if (_isPreview) { _previewIndex = 0; _previewLocation = 0; if (_currentClip == null || !_currentClip.Eligible) { MorphDebug.LogError("无法预览动画!当前未选中动画剪辑或选中的剪辑关键帧数小于2!", _skinnedMeshRenderer.gameObject); _isPreview = false; } } } MorphEditorTool.SetGUIEnabled(!_isPreview); if (GUILayout.Button(MorphStyle.IconGUIContent("Animation.NextKey"), "Toolbarbutton")) { if (_currentKeyframe != null) { int index = _currentClip.Keyframes.IndexOf(_currentKeyframe); index += 1; if (index >= _currentClip.Keyframes.Count) { index = 0; } SelectKeyframe(_currentClip.Keyframes[index]); } } GUILayout.FlexibleSpace(); if (GUILayout.Button("Create Clip", "Toolbarbutton")) { CreateClip(new Vector2(position.width / 2, position.height / 2)); } if (_currentClip != null) { if (GUILayout.Button("Rename Clip", "Toolbarbutton")) { _isRenameClip = !_isRenameClip; if (_isRenameClip) { _newNameClip = _currentClip.Name; } } if (GUILayout.Button("Delete Clip", "Toolbarbutton")) { if (EditorUtility.DisplayDialog("Prompt", "Whether to delete clip '" + _currentClip.Name + "'?This is unrecoverable.", "Sure", "Cancel")) { DeleteClip(_currentClip); } } } GUILayout.EndHorizontal(); }