blob: 12ba6fe493bc153a6210487ff369cef680126e94 (
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
95
96
97
98
99
100
101
102
103
104
105
106
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 每个角色拥有一个state system
/// </summary>
public class StateController
{
/// <summary>
/// 当前执行的state
/// </summary>
private StateBase m_Currrent;
public StateBase Current
{
get
{
return m_Currrent;
}
}
private List<StateBase> m_States = new List<StateBase>();
private UberState m_UberState;
public StateController()
{
}
public void ForceStart(StateBase state)
{
if (state == null)
return;
if (m_Currrent != null)
m_Currrent.OnExit();
m_Currrent = state;
m_Currrent.OnEnter();
}
public void SetUberState(UberState state)
{
m_UberState = state;
}
public void AddState(StateBase state)
{
m_States.Add(state);
}
public void OnUpdate()
{
if(m_Currrent != null)
{
m_Currrent.OnUpdate();
}
if(m_UberState != null)
{
m_UberState.OnUpdate();
}
}
public void OnPhysicsUpdate()
{
if(m_Currrent != null)
{
m_Currrent.OnPhysicsUpdate();
}
if(m_UberState != null)
{
m_UberState.OnPhysicsUpdate();
}
}
public void OnHit(HitInfo info)
{
if (m_Currrent != null)
m_Currrent.OnHit(info);
}
public void OnHurt(HurtInfo info)
{
if (m_Currrent != null)
m_Currrent.OnHurt(info);
}
public void SwitchToState(StateBase targetState)
{
if (m_Currrent != null)
m_Currrent.OnExit();
m_Currrent = targetState;
m_Currrent.OnEnter();
}
// 获得当前击打如果有的话
public Hit GetHit()
{
if (Current == null || !(Current is AttackState))
return null;
AttackState state = Current as AttackState;
return state.GetHit();
}
}
|