NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Game/GameStateStory.cs

67 lines
1.7 KiB
C#
Raw Normal View History

2023-11-17 13:14:55 +08:00
using Code.Scripts.Gameplay.Utils;
2023-10-19 15:00:19 +08:00
using Cysharp.Threading.Tasks;
using Framework;
2024-01-09 19:20:29 +08:00
using Gameplay;
2023-11-22 15:05:43 +08:00
using Gameplay.Level;
2023-10-19 15:00:19 +08:00
using Gameplay.Story;
2023-10-21 11:55:23 +08:00
using Gameplay.SubSystems;
2023-10-19 15:00:19 +08:00
namespace Code.Scripts.Gameplay.Game
{
public class GameStateStory : IState
{
2023-11-17 13:14:55 +08:00
private readonly cfg.StoryCfg.DataStoryMain _storyConfig;
2023-10-19 15:00:19 +08:00
2023-11-17 13:14:55 +08:00
private bool _isReady;
private bool _needExit;
2023-11-02 13:19:01 +08:00
2024-01-05 20:03:45 +08:00
public GameStateStory(string storyId)
2023-10-19 15:00:19 +08:00
{
_storyConfig = TableManager.Instance.Tables.StoryMainConfig.Get(storyId);
}
public void OnEnter()
{
2023-11-02 13:19:01 +08:00
_needExit = false;
2023-11-17 13:14:55 +08:00
_isReady = false;
2023-11-02 13:19:01 +08:00
EventManager.Instance.Register(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
2024-01-09 19:20:29 +08:00
var exe = new StoryLoadingExecutor(_storyConfig);
exe.OnEnd = delegate
{
_isReady = true;
};
LoadingExecutorManager.Instance.ExecuteLoading(exe);
2023-10-19 15:00:19 +08:00
}
2024-01-09 19:20:29 +08:00
2023-10-19 15:00:19 +08:00
2024-01-09 19:20:29 +08:00
2023-11-17 13:14:55 +08:00
2023-10-19 15:00:19 +08:00
public void OnUpdate(float deltaTime)
{
if (!_isReady) return;
2023-11-17 13:14:55 +08:00
2023-10-19 15:00:19 +08:00
StoryManager.instance.LogicUpdate(deltaTime);
2023-11-02 13:19:01 +08:00
}
private void _OnRecvExit()
{
_needExit = true;
2023-11-22 15:05:43 +08:00
if(LevelManager.Instance.IsInLevel)
LevelManager.Instance.TryExitLevel(true);
else
GameStateManager.Instance.ChangeState(new GameStateMainScene());
2023-10-19 15:00:19 +08:00
}
2023-11-17 13:14:55 +08:00
2023-10-19 15:00:19 +08:00
public void OnExit()
{
2023-11-02 13:19:01 +08:00
EventManager.Instance.Unregister(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
2023-10-19 15:00:19 +08:00
// TODO: 卸载场景
StoryManager.instance.DisposeForGame();
}
}
}