summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Component/MonsterAnimation.cs
blob: f536c5ef64f1d7f2b8347a458b81da1c72cc76a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterAnimation : UnitAnimation
{
    public enum ELayer
    {
        Basic = 0,

        Count,
    }

    // 动作名,和animator里的state对应
    public enum EAnimState
    {
        // layer 0 
        Idle = 0,
        Move,
        Jump,
        Hit,
        Attack,
        Rise,
        Stinger,
        Turn,
        Landing,

        AirAttack0,
        AirAttack1,
        AirAttack2,
        AirAttack3,

        Attack0,
        Attack1,
        Attack2,
        Attack3,
    }

    public override void Initialize()
    {
        base.Initialize();

        m_Animator = this.m_Owner.unitObj.GetComponent<Animator>();

        m_Animator.speed = 0;

        m_LayerInfo = new AnimatorLayerInfo[2];
        m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, (int)ELayer.Basic);
        //m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack);

        if (m_Animator == null)
        {
            LogHelper.LogError("没有挂Animator组件");
        }

    }

    public override void OnUpdate()
    {
        base.OnUpdate();

        UpdateLayer();
        UpdateAnimation();
        UpdateRootMotion();
    }

    void UpdateLayer()
    {
        m_LayerInfo[0].OnUpdate();
        return;
        for (int i = 0; i < m_LayerInfo.Length; ++i)
        {
            m_LayerInfo[i].OnUpdate();
        }
    }

    void UpdateAnimation()
    {
        m_Animator.speed = 1;
        m_Animator.Update(Time.deltaTime);
        m_Animator.speed = 0;
    }

    void UpdateRootMotion()
    {
        m_Owner.unitRootMotion.UpdateRootMotion();
    }


    public void AnimIdle()
    {
        m_Animator.CrossFade("Idle", 0.2f, 0);
    }
}