- 引入 UnityGameFramework
- 使用 Luban 替代原来的 UGF 的数据表
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using GameFramework.Event;
|
||||
using SepCore.Sound;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Utility;
|
||||
using UnityGameFramework.Runtime;
|
||||
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
|
||||
|
||||
namespace SepCore.Procedure
|
||||
{
|
||||
public class ProcedureChangeScene : ProcedureBase
|
||||
{
|
||||
private int _nextSceneId = 0;
|
||||
private bool _isChangeSceneComplete = false;
|
||||
private int _backgroundMusicId = 0;
|
||||
|
||||
protected override void OnEnter(ProcedureOwner procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
_isChangeSceneComplete = false;
|
||||
|
||||
GameEntry.Event.Subscribe(LoadSceneSuccessEventArgs.EventId, OnLoadSceneSuccess);
|
||||
GameEntry.Event.Subscribe(LoadSceneFailureEventArgs.EventId, OnLoadSceneFailure);
|
||||
GameEntry.Event.Subscribe(LoadSceneUpdateEventArgs.EventId, OnLoadSceneUpdate);
|
||||
GameEntry.Event.Subscribe(LoadSceneDependencyAssetEventArgs.EventId, OnLoadSceneDependencyAsset);
|
||||
|
||||
// 停止所有声音
|
||||
GameEntry.Sound.StopAllLoadingSounds();
|
||||
GameEntry.Sound.StopAllLoadedSounds();
|
||||
|
||||
// 隐藏所有实体
|
||||
GameEntry.Entity.HideAllLoadingEntities();
|
||||
GameEntry.Entity.HideAllLoadedEntities();
|
||||
|
||||
// 卸载所有场景
|
||||
string[] loadedSceneAssetNames = GameEntry.Scene.GetLoadedSceneAssetNames();
|
||||
for (int i = 0; i < loadedSceneAssetNames.Length; i++)
|
||||
{
|
||||
GameEntry.Scene.UnloadScene(loadedSceneAssetNames[i]);
|
||||
}
|
||||
|
||||
// 还原游戏速度
|
||||
GameEntry.Base.ResetNormalGameSpeed();
|
||||
|
||||
_nextSceneId = procedureOwner.GetData<VarInt32>("NextSceneId");
|
||||
|
||||
SceneConfig sceneConfig = GameEntry.Luban.Get<SceneConfig>(_nextSceneId);
|
||||
if (sceneConfig == null)
|
||||
{
|
||||
Log.Warning("Can not load scene '{0}' from data table.", _nextSceneId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.Scene.LoadScene(AssetUtility.GetSceneAsset(sceneConfig.AssetName), Constant.AssetPriority.SceneAsset,
|
||||
this);
|
||||
_backgroundMusicId = sceneConfig.BackgroundMusicId;
|
||||
}
|
||||
|
||||
protected override void OnLeave(ProcedureOwner procedureOwner, bool isShutdown)
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(LoadSceneSuccessEventArgs.EventId, OnLoadSceneSuccess);
|
||||
GameEntry.Event.Unsubscribe(LoadSceneFailureEventArgs.EventId, OnLoadSceneFailure);
|
||||
GameEntry.Event.Unsubscribe(LoadSceneUpdateEventArgs.EventId, OnLoadSceneUpdate);
|
||||
GameEntry.Event.Unsubscribe(LoadSceneDependencyAssetEventArgs.EventId, OnLoadSceneDependencyAsset);
|
||||
|
||||
base.OnLeave(procedureOwner, isShutdown);
|
||||
}
|
||||
|
||||
protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||
|
||||
if (!_isChangeSceneComplete)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SceneType sceneType = (SceneType)_nextSceneId;
|
||||
switch (sceneType)
|
||||
{
|
||||
case SceneType.Menu:
|
||||
ChangeState<ProcedureMenu>(procedureOwner);
|
||||
break;
|
||||
case SceneType.Main:
|
||||
ChangeState<ProcedureMain>(procedureOwner);
|
||||
break;
|
||||
default:
|
||||
Log.Debug($"Scene {sceneType.ToString()} don't configure a procedure");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoadSceneSuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
LoadSceneSuccessEventArgs ne = (LoadSceneSuccessEventArgs)e;
|
||||
if (ne.UserData != this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Info("Load scene '{0}' OK.", ne.SceneAssetName);
|
||||
|
||||
if (_backgroundMusicId > 0)
|
||||
{
|
||||
GameEntry.Sound.PlayMusic(_backgroundMusicId);
|
||||
}
|
||||
|
||||
_isChangeSceneComplete = true;
|
||||
}
|
||||
|
||||
private void OnLoadSceneFailure(object sender, GameEventArgs e)
|
||||
{
|
||||
LoadSceneFailureEventArgs ne = (LoadSceneFailureEventArgs)e;
|
||||
if (ne.UserData != this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Error("Load scene '{0}' failure, error message '{1}'.", ne.SceneAssetName, ne.ErrorMessage);
|
||||
}
|
||||
|
||||
private void OnLoadSceneUpdate(object sender, GameEventArgs e)
|
||||
{
|
||||
LoadSceneUpdateEventArgs ne = (LoadSceneUpdateEventArgs)e;
|
||||
if (ne.UserData != this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Info("Load scene '{0}' update, progress '{1}'.", ne.SceneAssetName, ne.Progress.ToString("P2"));
|
||||
}
|
||||
|
||||
private void OnLoadSceneDependencyAsset(object sender, GameEventArgs e)
|
||||
{
|
||||
LoadSceneDependencyAssetEventArgs ne = (LoadSceneDependencyAssetEventArgs)e;
|
||||
if (ne.UserData != this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Info("Load scene '{0}' dependency asset '{1}', count '{2}/{3}'.", ne.SceneAssetName,
|
||||
ne.DependencyAssetName, ne.LoadedCount.ToString(), ne.TotalCount.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user