82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using Code.Scripts.Gameplay.Utils;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
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(int storyId)
|
|
{
|
|
_storyConfig = TableManager.Instance.Tables.StoryMainConfig.Get(storyId);
|
|
}
|
|
|
|
public void OnEnter()
|
|
{
|
|
_needExit = false;
|
|
_isReady = false;
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
|
|
_AsyncAction();
|
|
}
|
|
|
|
private async void _AsyncAction()
|
|
{
|
|
|
|
await _LoadScene();
|
|
|
|
// 设置阴影距离
|
|
ShadowEx.SetShadowDistance(_storyConfig.ShadowDistance);
|
|
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;
|
|
if(LevelManager.Instance.IsInLevel)
|
|
LevelManager.Instance.TryExitLevel(true);
|
|
else
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene());
|
|
}
|
|
|
|
public void OnExit()
|
|
{
|
|
UIManager.Instance.CloseAllUI(UIWindowCloseType.HideAndDestroy);
|
|
EventManager.Instance.Unregister(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
|
|
// TODO: 卸载场景
|
|
StoryManager.instance.DisposeForGame();
|
|
}
|
|
}
|
|
}
|