Пример #1
0
        public void UpdateAnim(float dt)
        {
            if (TargetSpriteRenderer == null || m_dirAnimCtrl == null)
            {
                return;
            }

            m_animIdx = (m_animIdx + m_dirAnimCtrl.GetAnimList().Count) % m_dirAnimCtrl.GetAnimList().Count;
            DirectionalAnimData anim = m_dirAnimCtrl.GetAnim(m_animIdx);

            if (IsPlaying)
            {
                if (IsPingPongAnim && (m_internalFrame == 0 || m_internalFrame == (anim.FramesPerDir - 1)))
                {
                    m_curFrameTime += dt * AnimSpeed * 2f; // avoid stay twice of the time in the first and last frame of the animation
                }
                else
                {
                    m_curFrameTime += dt * AnimSpeed;
                }
                while (m_curFrameTime >= 1f)
                {
                    m_curFrameTime -= 1f;
                    ++m_internalFrame; m_internalFrame %= anim.FramesPerDir;
                    if (m_internalFrame == 0)
                    {
                        if (OnAnimationLoopOver != null)
                        {
                            OnAnimationLoopOver(this);
                        }
                        m_isPingPongReverse = !m_isPingPongReverse;
                    }
                }
            }
            else
            {
                m_isPingPongReverse = false;
                if (m_stopFrameIdx >= 0)
                {
                    if (m_stopFrameIdx >= anim.FramesPerDir)
                    {
                        m_stopFrameIdx %= anim.FramesPerDir;
                    }
                    m_internalFrame = m_stopFrameIdx;
                }
            }

            TargetSpriteRenderer.sprite = GetCurrentSprite(AnimDirection);
        }
        public override void OnInspectorGUI()
        {
            Event e = Event.current;

            serializedObject.Update();

            //DrawDefaultInspector();
            m_dirMappingReordList.DoLayoutList();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_dirType"), new GUIContent("Directions"));
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_spriteAlignment"));
            GUI.enabled = m_target.SpriteAlignment == SpriteAlignment.Custom;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_pivot"));
            GUI.enabled = true;
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                UpdateAligmentAndPivotAll();
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_fpa"), new GUIContent("Animation Frames", "How many frames each direction have."));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_fps"), new GUIContent("Animation Speed", "Frames per second."));

            if (GUILayout.Button("Clear All Animations") && EditorUtility.DisplayDialog("Clear All Animations", "Are you sure to clear all animations?", "Yes", "No"))
            {
                Undo.RegisterCompleteObjectUndo(target, "Clear All Animations");
                m_target.GetAnimList().Clear();
                serializedObject.Update();
            }

            if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Delete)
            {
                Undo.RegisterCompleteObjectUndo(target, "Remove Character Animation");
                ReorderableList.defaultBehaviours.DoRemoveButton(m_animReordList);
            }
            m_animReordList.headerHeight  = 64f;
            m_animReordList.elementHeight = m_target.DirectionsPerAnim <= 4? 64f : 128f;
            m_animReordList.DoLayoutList();

            Repaint();
            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }