You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
5.4 KiB
C#
205 lines
5.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Articy.Touhou;
|
|
|
|
/// <summary>
|
|
/// 关卡池化管理
|
|
/// </summary>
|
|
namespace Game
|
|
{
|
|
public enum ELevelType
|
|
{
|
|
Home,
|
|
Battle,
|
|
BattleElite,
|
|
BattleBoss,
|
|
BattleBigBoss,
|
|
BattleFinalBoss,
|
|
Store,
|
|
Treasure,
|
|
Money,
|
|
Random,
|
|
Drama,
|
|
Rest,
|
|
None = 99,
|
|
}
|
|
|
|
public class LevelPoolManager : ObjectPoolBase<LevelPoolManager>
|
|
{
|
|
private const string LevelPath = "Level/";
|
|
private LevelPoolItem _curLevel;
|
|
private readonly List<string> _finishedLevel = new List<string>();
|
|
private float _loadingTimeLeft;
|
|
|
|
private readonly Dictionary<ELevelType, string>
|
|
_doorTypeDict = new Dictionary<ELevelType, string>(); //关卡类型对应门的实体id
|
|
|
|
public override void Update()
|
|
{
|
|
if (_loadingTimeLeft == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_loadingTimeLeft -= Time.deltaTime;
|
|
if (_loadingTimeLeft <= 0)
|
|
{
|
|
_loadingTimeLeft = 0;
|
|
Loading(false);
|
|
}
|
|
}
|
|
|
|
public override void OnDestroy()
|
|
{
|
|
}
|
|
|
|
public void EnterLevel(string levelId)
|
|
{
|
|
if (string.IsNullOrEmpty(levelId))
|
|
{
|
|
Util.Print("关卡id为空");
|
|
return;
|
|
}
|
|
|
|
if (_curLevel != null)
|
|
{
|
|
_curLevel.Destroy();
|
|
}
|
|
|
|
EnterLevelReal(levelId);
|
|
}
|
|
|
|
private void EnterLevelReal(string levelId)
|
|
{
|
|
Loading(true);
|
|
var levelNew = Create<LevelPoolItem>($"Level{levelId.ToString()}", (item) =>
|
|
{
|
|
var cfg = Util.GetConfig(levelId);
|
|
if (!(cfg is Level))
|
|
{
|
|
Util.Print("关卡id错误:", levelId);
|
|
return;
|
|
}
|
|
|
|
var cfgLevel = cfg as Level;
|
|
item.CfgId = cfg.TechnicalName;
|
|
item.Cfg = cfgLevel.GetFeatureLevel();
|
|
item.Init();
|
|
});
|
|
levelNew.SetPlayerBorn(_curLevel == null ? "" : _curLevel.CfgId);
|
|
_finishedLevel.Add(levelNew.CfgId);
|
|
_curLevel = levelNew;
|
|
_curLevel.CreateLevel();
|
|
}
|
|
|
|
public GameObject CreateLevelGo(string levelId)
|
|
{
|
|
var path = $"{LevelPath}{levelId.ToString()}";
|
|
var go = PrefabManager.Instance.CreateGo(path);
|
|
go.transform.parent = Root.transform;
|
|
return go;
|
|
}
|
|
|
|
private void Loading(bool isLoading)
|
|
{
|
|
if (isLoading)
|
|
{
|
|
_loadingTimeLeft = GameConst.LoadingMinTime;
|
|
UIManager.Instance.OpenInNew(EuiPage.Loading);
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.OpenInNew(EuiPage.Hud);
|
|
|
|
// TODO 显示关卡名称
|
|
// string levelName = m_CurLevel.m_LevelNode.Text;
|
|
// if (!string.IsNullOrEmpty(levelName))
|
|
// {
|
|
// EventManager.instance.SendEvent(EEvent.ShowLevelName, levelName);
|
|
// }
|
|
}
|
|
}
|
|
|
|
private void LoadDoorTypeDict()
|
|
{
|
|
var cfgs = Util.GetDoorConfigDataAll();
|
|
foreach (var item in cfgs)
|
|
{
|
|
var cfg = item.Template.Door;
|
|
_doorTypeDict[(ELevelType)cfg.LevelType] = item.TechnicalName;
|
|
}
|
|
}
|
|
|
|
public string GetDoorId(ELevelType levelType)
|
|
{
|
|
if (!_doorTypeDict.ContainsKey(levelType))
|
|
{
|
|
Util.Print("无该类型的传送门:", levelType);
|
|
return "";
|
|
}
|
|
|
|
return _doorTypeDict[levelType];
|
|
}
|
|
|
|
public LevelPoolItem GetCurLevel()
|
|
{
|
|
return _curLevel;
|
|
}
|
|
|
|
public ILevelMonsterWave GetCurWave()
|
|
{
|
|
return _curLevel.CurWave ? _curLevel.CurWave : LevelNodeMonsterWave.Default;
|
|
}
|
|
|
|
public bool IsLevelLoading()
|
|
{
|
|
return _loadingTimeLeft > 0;
|
|
}
|
|
|
|
public List<string> GetFinishedLevel()
|
|
{
|
|
return _finishedLevel;
|
|
}
|
|
|
|
public int GetDifficulty()
|
|
{
|
|
return _curLevel.Cfg.Difficulty;
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace Game
|
|
{
|
|
public abstract partial class Util
|
|
{
|
|
public static void EnterLevel(string levelId)
|
|
{
|
|
LevelPoolManager.Instance.EnterLevel(levelId);
|
|
}
|
|
|
|
public static LevelPoolItem GetCurLevel()
|
|
{
|
|
return LevelPoolManager.Instance.GetCurLevel();
|
|
}
|
|
|
|
public static ILevelMonsterWave GetCurWave()
|
|
{
|
|
return LevelPoolManager.Instance.GetCurWave();
|
|
}
|
|
|
|
public static int GetDifficulty()
|
|
{
|
|
return LevelPoolManager.Instance.GetDifficulty();
|
|
}
|
|
|
|
public static bool IsLevelLoading()
|
|
{
|
|
return LevelPoolManager.Instance.IsLevelLoading();
|
|
}
|
|
|
|
public static List<string> GetFinishedLevel()
|
|
{
|
|
return LevelPoolManager.Instance.GetFinishedLevel();
|
|
}
|
|
}
|
|
} |