using Code.Scripts.Gameplay.Utils; using Cysharp.Threading.Tasks; using Framework; using Gameplay; using Gameplay.Effect; using Gameplay.Level; using Gameplay.Story; using Gameplay.SubSystems; namespace Code.Scripts.Gameplay.Game { public class GameStateStory : IState { private readonly cfg.StoryCfg.DataStoryMain _storyConfig; private bool _isReady; private bool _needExit; public GameStateStory(string storyId) { _storyConfig = TableManager.Instance.Tables.StoryMainConfig.Get(storyId); } public void OnEnter() { _needExit = false; _isReady = false; EventManager.Instance.Register(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit); var exe = new StoryLoadingExecutor(_storyConfig); exe.OnEnd = delegate { _isReady = true; }; LoadingExecutorManager.Instance.ExecuteLoading(exe); } public void OnUpdate(float deltaTime) { if (!_isReady) return; StoryManager.instance.LogicUpdate(deltaTime); } private void _OnRecvExit() { _needExit = true; if(LevelManager.Instance.IsInLevel) LevelManager.Instance.TryExitLevel(true); else GameStateManager.Instance.ChangeState(new GameStateMainScene()); } public void OnExit() { EventManager.Instance.Unregister(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit); StoryManager.instance.DisposeForGame(); EffectManager.instance.ClearPool(); GameSceneManager.Instance.UnLoadSceneAsync(_storyConfig.ScenePath).Forget(); } } }