public void Init(SkinnedMeshRenderer skinnedMesh, MorphAnimationData data, MorphAnimator animator)
        {
            _skinnedMeshRenderer = skinnedMesh;
            _morphAnimationData  = data;
            _morphAnimator       = animator;

            _currentClip       = null;
            _currentKeyframe   = null;
            _currentBone       = null;
            _currentBoneParent = null;
            _keepingDistance   = 0;

            _isRecord                   = false;
            _isPreview                  = false;
            _previewIndex               = 0;
            _previewLocation            = 0;
            _isRenameClip               = false;
            _newNameClip                = "";
            _keyframeView               = Vector2.zero;
            _clipSizeWidth              = 150;
            _clipSizeHeight             = 30;
            _moveCenter                 = Vector2.zero;
            _keyframePropertyViewWidth  = 0;
            _keyframePropertyViewHeight = 0;
            _keyframePropertyView       = Vector2.zero;
            _boneNameFiltrate           = "";
            _clipPropertyViewWidth      = 0;
            _clipPropertyViewHeight     = 0;

            ReviewClips();
        }
        private void DeleteClip(MorphAnimationClip clip)
        {
            int index = _morphAnimator.Clips.IndexOf(clip);

            if (_morphAnimator.DefaultClipIndex >= index)
            {
                _morphAnimator.DefaultClipIndex -= 1;
            }

            _morphAnimator.Clips.Remove(clip);
            _currentClip     = null;
            _currentKeyframe = null;

            if (_morphAnimator.DefaultClipIndex == -1 && _morphAnimator.Clips.Count > 0)
            {
                _morphAnimator.DefaultClipIndex = 0;
            }

            for (int i = 0; i < _morphAnimator.Clips.Count; i++)
            {
                if (_morphAnimator.Clips[i].TransitionClip == index)
                {
                    _morphAnimator.Clips[i].TransitionClip = -1;
                }
                else if (_morphAnimator.Clips[i].TransitionClip > index)
                {
                    _morphAnimator.Clips[i].TransitionClip -= 1;
                }
            }
        }
Exemplo n.º 3
0
        private void SwitchClip(MorphAnimationClip clip)
        {
            _currentClip = clip;

            if (!_currentClip.Valid)
            {
                _updateAnimation = null;
                MorphDebug.LogError("动画剪辑 " + _currentClip.Name + " 是无效的!", gameObject);
                return;
            }

            if (!_currentClip.Eligible)
            {
                _updateAnimation = null;
                MorphDebug.LogError("动画剪辑 " + _currentClip.Name + " 无法播放,可能其并未拥有至少两个关键帧!", gameObject);
                return;
            }

            _playIndex    = 0;
            _playLocation = 0;

            if (_currentClip.TransitionClip != -1 && Clips[_currentClip.TransitionClip].Valid && Clips[_currentClip.TransitionClip].Eligible)
            {
                _updateAnimation = UpdateAnimationTransition;
            }
            else
            {
                _updateAnimation = UpdateAnimationLoop;
            }

            EventCallBack(_currentClip.Keyframes[_playIndex]);
        }
        private void CreateClip(Vector2 anchor)
        {
            MorphAnimationClip clip = new MorphAnimationClip("NewClip" + _morphAnimator.Clips.Count, _skinnedMeshRenderer.bones.Length, anchor);

            _morphAnimator.Clips.Add(clip);

            if (_morphAnimator.DefaultClipIndex == -1)
            {
                _morphAnimator.DefaultClipIndex = 0;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 切换动画状态,Change animation state
        /// </summary>
        /// <param name="state">要切换到的动画剪辑的名称,Animation clip name</param>
        public void SwitchState(string state)
        {
            if (_skinnedMeshRenderer == null)
            {
                _updateAnimation = null;
                MorphDebug.LogError("物体丢失了 SkinnedMeshRenderer 组件!", gameObject);
                return;
            }

            MorphAnimationClip clip = Clips.Find((c) => { return(c.Name == state); });

            if (clip != null)
            {
                SwitchClip(clip);
            }
        }
 private void SelectClip(MorphAnimationClip clip)
 {
     _currentClip     = clip;
     _currentKeyframe = null;
 }
        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 KeyframeGUI()
        {
            if (_currentClip != null)
            {
                GUILayout.BeginHorizontal("Toolbar");
                if (GUILayout.Button(_currentClip.Name, "ToolbarPopup", GUILayout.Width(100)))
                {
                    GenericMenu gm = new GenericMenu();
                    for (int i = 0; i < _morphAnimator.Clips.Count; i++)
                    {
                        MorphAnimationClip clip = _morphAnimator.Clips[i];
                        if (clip.Valid)
                        {
                            gm.AddItem(new GUIContent(clip.Name), _currentClip == clip, () =>
                            {
                                SelectClip(clip);
                            });
                        }
                    }
                    gm.ShowAsContext();
                }
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add Keyframe", "Toolbarbutton"))
                {
                    CreateKeyframe();
                }
                if (_currentKeyframe != null)
                {
                    if (GUILayout.Button("Clone Keyframe", "Toolbarbutton"))
                    {
                        CloneKeyframe();
                    }
                    if (GUILayout.Button("Delete Keyframe", "Toolbarbutton"))
                    {
                        if (EditorUtility.DisplayDialog("Prompt", "Whether to delete current keyframe?This is unrecoverable.", "Sure", "Cancel"))
                        {
                            DeleteKeyframe();
                        }
                    }
                }
                GUILayout.EndHorizontal();

                _keyframeView = GUILayout.BeginScrollView(_keyframeView);
                GUILayout.BeginHorizontal("Box");
                GUILayout.Label("Keyframes:");
                if (_currentClip.Keyframes.Count <= 0)
                {
                    GUILayout.Label("Please add a keyframe!");
                }
                else
                {
                    for (int i = 0; i < _currentClip.Keyframes.Count; i++)
                    {
                        bool value = (_currentKeyframe == _currentClip.Keyframes[i]);
                        MorphEditorTool.SetGUIColor(_currentClip.Keyframes[i].EventCallBack.CallTarget ? Color.cyan : Color.white);
                        if (GUILayout.Toggle(value, (i + 1).ToString(), "PreButton") != value)
                        {
                            SelectKeyframe(_currentClip.Keyframes[i]);
                        }
                    }
                    MorphEditorTool.SetGUIColor(Color.white);
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Please select a clip!");
                GUILayout.EndHorizontal();
            }
        }