UI工具翻新
1. 增加UI工具 2. 增加设置页面 3. GameLoop更新 4. 导入ActionKit工具
This commit is contained in:
@@ -0,0 +1,223 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class GameManager : Singleton<GameManager>, IGameManager
|
||||
{
|
||||
#region 运行模式相关
|
||||
|
||||
[Header("可用so合集")] public TalkSceneSO[] totalSceneSos;
|
||||
|
||||
public RunMode runMode;
|
||||
|
||||
[Header("生产环境数据(一般不动)")] public TalkSceneSO firstTalkSo;
|
||||
[Header("单场景测试")] public TalkSceneSO testTalkSo;
|
||||
[Header("存档测试")] public string saveFileName;
|
||||
|
||||
#endregion
|
||||
|
||||
private BindProperty<TalkSceneSO> _currentTalkSceneSo;
|
||||
private readonly GameLoopData _data = new();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 管理游戏开始时各部分的初始化
|
||||
SettingLoader.Init();
|
||||
// 数据类注册
|
||||
StorageSystem.Instance.RegisterData(_data);
|
||||
SceneLoader.Instance.LoadScene("ClinicOut");
|
||||
// 场景So事件注册
|
||||
_currentTalkSceneSo = new BindProperty<TalkSceneSO>();
|
||||
_currentTalkSceneSo.Register(item => _data.curSceneSoName = item.name);
|
||||
// 事件广播
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.AppStart);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (runMode == RunMode.SingleScene)
|
||||
{
|
||||
StartWithLevel(testTalkSo);
|
||||
}
|
||||
else if (runMode == RunMode.SaveFile)
|
||||
{
|
||||
StartWithSaveFile($"{ConstRef.TestSaveFilePath}/{saveFileName}");
|
||||
}
|
||||
#else
|
||||
runMode = RunMode.Product;
|
||||
#endif
|
||||
}
|
||||
|
||||
#region 游戏循环
|
||||
|
||||
public void StartNewGame()
|
||||
{
|
||||
// 游戏开始
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.GameStart);
|
||||
// 序列
|
||||
_currentTalkSceneSo.Value = firstTalkSo;
|
||||
StartCoroutine(LoadFirstScene());
|
||||
}
|
||||
|
||||
public void StartWithLevel(TalkSceneSO sceneSo)
|
||||
{
|
||||
// 游戏开始
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.GameStart);
|
||||
|
||||
_currentTalkSceneSo.Value = sceneSo;
|
||||
StartCoroutine(LoadFirstScene());
|
||||
}
|
||||
|
||||
public void StartWithSaveFile(string fileName)
|
||||
{
|
||||
// 游戏开始
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.GameStart);
|
||||
|
||||
StorageSystem.Instance.Load(fileName);
|
||||
}
|
||||
|
||||
private IEnumerator LoadFirstScene()
|
||||
{
|
||||
yield return SceneLoader.Instance.LoadSceneAsync(_currentTalkSceneSo.Value.firstSceneName);
|
||||
DialogController.Instance.StartDialog(_currentTalkSceneSo.Value.yarnProject);
|
||||
}
|
||||
|
||||
public void PauseGame()
|
||||
{
|
||||
// 系统暂停
|
||||
Time.timeScale = 0;
|
||||
// 交互暂停
|
||||
CursorManager.Instance.isPaused = true;
|
||||
// 音频全部暂停
|
||||
AudioManager.Instance.PauseAll();
|
||||
}
|
||||
|
||||
public void ContinueGame()
|
||||
{
|
||||
// 系统继续
|
||||
Time.timeScale = 1;
|
||||
// 交互继续
|
||||
CursorManager.Instance.isPaused = false;
|
||||
// 音频继续
|
||||
AudioManager.Instance.UnPauseAll();
|
||||
}
|
||||
|
||||
public void QuitGame()
|
||||
{
|
||||
// 系统继续
|
||||
Time.timeScale = 1;
|
||||
// 交互继续
|
||||
CursorManager.Instance.isPaused = true;
|
||||
// 卸载当前场景
|
||||
StartCoroutine(RestartCoroutine());
|
||||
// 音频继续
|
||||
AudioManager.Instance.UnPauseAll();
|
||||
}
|
||||
|
||||
public void QuitApp()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
private IEnumerator RestartCoroutine()
|
||||
{
|
||||
yield return UIManager.Instance.GetPanel<PlayToolPanel>().FadeInAsync();
|
||||
|
||||
// 执行场景切换等功能
|
||||
yield return SceneLoader.Instance.LoadSceneAsync("ClinicOut");
|
||||
DialogController.Instance.StopDialog();
|
||||
EnumEventSystem.Global.Send(GameLoopEnum.GameQuit);
|
||||
|
||||
yield return UIManager.Instance.GetPanel<PlayToolPanel>().FadeOutAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public IEnumerator NextSceneSo()
|
||||
{
|
||||
if (_currentTalkSceneSo.Value && _currentTalkSceneSo.Value.nextScene)
|
||||
{
|
||||
_currentTalkSceneSo.Value = _currentTalkSceneSo.Value.nextScene;
|
||||
yield return UIManager.Instance.GetPanel<PlayToolPanel>().FadeInAsync();
|
||||
yield return SceneLoader.Instance.LoadSceneAsync(_currentTalkSceneSo.Value.firstSceneName);
|
||||
DialogController.Instance.StartDialog(_currentTalkSceneSo.Value.yarnProject);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return null;
|
||||
Debug.Log("没有下个场景了");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSceneSoByName(string soName)
|
||||
{
|
||||
_currentTalkSceneSo.Value = Array.Find(totalSceneSos, so => so.name == soName);
|
||||
}
|
||||
|
||||
public void StartDialog()
|
||||
{
|
||||
DialogController.Instance.LoadDialog(_currentTalkSceneSo.Value.yarnProject);
|
||||
}
|
||||
|
||||
public string GetSceneSoName()
|
||||
{
|
||||
return _currentTalkSceneSo.Value.name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GameManager应该包含什么功能?
|
||||
/// 1. 游戏状态管理。开始/暂停/结束
|
||||
/// 2. 全局设置 即SettingLoader
|
||||
/// 3. 场景管理 有SceneLoader类,暂无必要
|
||||
/// 4. 资源管理 似无必要
|
||||
/// 5. 时间管理 主要供暂停使用
|
||||
/// 6. 日志和调试 日志已有
|
||||
/// </summary>
|
||||
public interface IGameManager
|
||||
{
|
||||
#region 游戏循环相关
|
||||
|
||||
public void StartNewGame();
|
||||
public void PauseGame();
|
||||
public void ContinueGame();
|
||||
public void QuitGame();
|
||||
public void QuitApp();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[LoadIndex(10)]
|
||||
public class GameLoopData : IData
|
||||
{
|
||||
public string curSceneSoName;
|
||||
|
||||
public IEnumerator Load()
|
||||
{
|
||||
GameManager.Instance.SetSceneSoByName(curSceneSoName);
|
||||
GameManager.Instance.StartDialog();
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
public static class GameLoopYarnCommand
|
||||
{
|
||||
[YarnCommand("auto_save")]
|
||||
public static void AutoSave()
|
||||
{
|
||||
StorageSystem.Instance.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public enum RunMode
|
||||
{
|
||||
Product,
|
||||
SingleScene,
|
||||
SaveFile
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user