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;
|
2024-03-04 19:32:32 +08:00
|
|
|
using Gameplay.Effect;
|
2024-07-05 21:26:37 +08:00
|
|
|
using Gameplay.Guide;
|
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;
|
2024-07-05 12:18:35 +08:00
|
|
|
public cfg.StoryCfg.DataStoryMain storyConfig
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _storyConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
2023-11-17 13:14:55 +08:00
|
|
|
private bool _isReady;
|
2024-06-27 13:22:21 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 记录剧情关卡加载完成后是否立即播放
|
|
|
|
|
/// </summary>
|
2024-07-05 12:18:35 +08:00
|
|
|
private bool _autoPlay;
|
2023-11-17 13:14:55 +08:00
|
|
|
|
|
|
|
|
private bool _needExit;
|
2023-11-02 13:19:01 +08:00
|
|
|
|
2024-06-27 13:22:21 +08:00
|
|
|
public bool IsReady
|
|
|
|
|
{
|
|
|
|
|
set { _isReady = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 12:18:35 +08:00
|
|
|
public GameStateStory(string storyId, bool autoPlay = true)
|
2023-10-19 15:00:19 +08:00
|
|
|
{
|
|
|
|
|
_storyConfig = TableManager.Instance.Tables.StoryMainConfig.Get(storyId);
|
2024-07-05 12:18:35 +08:00
|
|
|
_autoPlay = autoPlay;
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2024-07-05 12:18:35 +08:00
|
|
|
_isReady = _autoPlay;
|
2024-01-09 19:20:29 +08:00
|
|
|
};
|
2024-05-17 19:27:02 +08:00
|
|
|
LoadingExecutorManager.Instance.ExecuteLoading(exe).Forget();
|
2024-06-04 15:13:16 +08:00
|
|
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.Guide_ChangeStoryState);
|
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)
|
|
|
|
|
{
|
2024-07-08 12:28:01 +08:00
|
|
|
if (_needExit) return;
|
2023-10-19 15:00:19 +08:00
|
|
|
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()
|
|
|
|
|
{
|
2024-07-08 12:28:01 +08:00
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.STORY_CLICK_SKIP, _OnRecvExit);
|
2023-11-02 13:19:01 +08:00
|
|
|
_needExit = true;
|
2024-07-05 21:26:37 +08:00
|
|
|
if (LevelManager.Instance.IsInLevel)
|
2023-11-22 15:05:43 +08:00
|
|
|
LevelManager.Instance.TryExitLevel(true);
|
|
|
|
|
else
|
2024-07-05 21:26:37 +08:00
|
|
|
{
|
|
|
|
|
if (GuideManager.Instance.IsGuiding) // TODO 临时处理
|
|
|
|
|
return;
|
|
|
|
|
|
2023-11-22 15:05:43 +08:00
|
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene());
|
2024-07-05 21:26:37 +08:00
|
|
|
}
|
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()
|
|
|
|
|
{
|
|
|
|
|
StoryManager.instance.DisposeForGame();
|
2024-03-04 19:32:32 +08:00
|
|
|
EffectManager.instance.ClearPool();
|
2024-03-22 12:09:11 +08:00
|
|
|
GameSceneManager.Instance.UnLoadSceneAsync(_storyConfig.ScenePath).Forget();
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|