73 lines
1.8 KiB
C#
73 lines
1.8 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay.Story;
|
|
using Gameplay.SubSystems;
|
|
using PhxhSDK;
|
|
|
|
namespace Code.Scripts.Gameplay.Game
|
|
{
|
|
public class GameStateStory : IState
|
|
{
|
|
|
|
private cfg.StoryCfg.DataStoryMain _storyConfig;
|
|
|
|
private bool _isReady = false;
|
|
|
|
private bool _needExit = false;
|
|
|
|
public GameStateStory(int storyId)
|
|
{
|
|
_storyConfig = TableManager.Instance.Tables.StoryMainConfig.Get(storyId);
|
|
}
|
|
|
|
public void OnEnter()
|
|
{
|
|
_needExit = false;
|
|
EventManager.Instance.Register(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
|
|
_AsyncAction();
|
|
}
|
|
|
|
private async void _AsyncAction()
|
|
{
|
|
_isReady = false;
|
|
|
|
await _LoadScene();
|
|
|
|
StoryManager.instance.InitForGame();
|
|
await UIManager.Instance.OpenWindow(UINameConst.UIStoryMain);
|
|
|
|
_isReady = true;
|
|
}
|
|
|
|
private async UniTask _LoadScene()
|
|
{
|
|
var scenePath = _storyConfig.ScenePath;
|
|
await GameSceneManager.Instance.LoadSceneAsync(scenePath);
|
|
}
|
|
|
|
public void OnUpdate(float deltaTime)
|
|
{
|
|
if (!_isReady) return;
|
|
|
|
StoryManager.instance.LogicUpdate(deltaTime);
|
|
|
|
if (_needExit)
|
|
{
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene());
|
|
}
|
|
}
|
|
|
|
private void _OnRecvExit()
|
|
{
|
|
_needExit = true;
|
|
}
|
|
|
|
public void OnExit()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
|
|
// TODO: 卸载场景
|
|
StoryManager.instance.DisposeForGame();
|
|
}
|
|
}
|
|
}
|