blob: bb637321e1919ac5fe4c737d66a2c2a3339fdb52 (
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
|
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditorInternal;
using UnityEngine;
using WK.Tools;
namespace WK
{
/// <summary>
/// 游戏最上层的状态机
/// </summary>
public sealed class GamePhaseManager : Singleton<GamePhaseManager>, ISubsystem
{
private AsyncStatemachine m_Statemachine;
private int[] phases = new int[(int)EGamePhase.Num];
private EGamePhase prevPhase = EGamePhase.Launch;
private EGamePhase curPhase = EGamePhase.Launch;
public void OnAwake()
{
SetupGamePhases();
}
private void SetupGamePhases()
{
m_Statemachine = new AsyncStatemachine();
phases[(int)EGamePhase.Launch] = m_Statemachine.RegisterState(new GamePhase_Launch());
phases[(int)EGamePhase.Main] = m_Statemachine.RegisterState(new GamePhase_Main());
phases[(int)EGamePhase.Battle] = m_Statemachine.RegisterState(new GamePhase_Battle());
phases[(int)EGamePhase.Dojo] = m_Statemachine.RegisterState(new GamePhase_Dojo());
m_Statemachine.Start(phases[(int)EGamePhase.Launch]);
}
public void OnStart()
{
}
public void OnUpdate()
{
m_Statemachine.Update(Time.deltaTime);
}
public void OnFixedUpdate()
{
}
public void OnDestroy()
{
}
public void OnApplicationPause()
{
}
public void OnApplicationQuit()
{
}
public void AsyncLoadPhase(EGamePhase phase, bool forceLoad = false, AsyncStatemachine.LoadStateComplete loadStateComplete = null)
{
int curRunPhase = m_Statemachine.GetCurStateID();
if (!forceLoad && curRunPhase == phases[(int)phase])
{
if (null != loadStateComplete)
{
loadStateComplete();
}
return;
}
//LogHelper.LogEditorError("==> PhaseChange:" + curPhase + " --> " + (EGamePhase)phase);
prevPhase = curPhase;
curPhase = phase;
m_Statemachine.GotoState(phases[(int)phase], false, forceLoad, loadStateComplete);
}
public EGamePhase GetCurPhase()
{
return curPhase;
}
public EGamePhase GetPrevPhase()
{
return prevPhase;
}
}
}
|