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

82 lines
2.2 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;
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
2023-10-19 15:00:19 +08:00
public GameStateStory(int storyId)
{
_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);
2023-10-19 15:00:19 +08:00
_AsyncAction();
}
private async void _AsyncAction()
{
await _LoadScene();
2023-11-17 13:14:55 +08:00
// 设置阴影距离
ShadowEx.SetShadowDistance(_storyConfig.ShadowDistance);
2023-10-19 15:00:19 +08:00
StoryManager.instance.InitForGame();
await UIManager.Instance.OpenWindow(UINameConst.UIStoryMain);
_isReady = true;
}
private async UniTask _LoadScene()
{
var scenePath = _storyConfig.ScenePath;
2023-10-21 11:55:23 +08:00
await GameSceneManager.Instance.LoadSceneAsync(scenePath);
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 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
2023-11-22 15:05:43 +08:00
// if (_needExit)
// {
// GameStateManager.Instance.ChangeState(new GameStateMainScene());
// }
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-22 15:36:39 +08:00
UIManager.Instance.CloseAllUI(UIWindowCloseType.HideAndDestroy);
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();
}
}
}