2023-10-19 15:00:19 +08:00
|
|
|
|
using cfg.LevelCfg;
|
|
|
|
|
|
using System.Collections.Generic;
|
2023-10-26 16:04:03 +08:00
|
|
|
|
using Code.Scripts.Gameplay.Enviorment;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using Framework;
|
|
|
|
|
|
using Gameplay.AI;
|
|
|
|
|
|
using Gameplay.Buff;
|
|
|
|
|
|
using Gameplay.Character;
|
|
|
|
|
|
using Gameplay.Common;
|
|
|
|
|
|
using Gameplay.Effect;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Gameplay.Emoji;
|
|
|
|
|
|
using Gameplay.Pool;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
using Gameplay.Skill;
|
|
|
|
|
|
using Gameplay.Vehicle;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using PhxhSDK;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
using UnityEngine;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Constants = Framework.Constants;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Gameplay.Level
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class Level : IUpdatable, ILoadable
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private int _id;
|
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
private LevelData _levelData;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private DataLevel _cfg;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
private Map _map;
|
|
|
|
|
|
private CharacterManager _characterManager = new CharacterManager();
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private StateMachine _stateMachine = new StateMachine();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public bool isInBattle = false;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
public int ID => _id;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public Map Map => _map;
|
2023-10-26 16:04:03 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public CharacterManager CharacterManager => _characterManager;
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public float LevelTime { set; get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Level(int leveId)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
_id = leveId;
|
|
|
|
|
|
Init();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private Dictionary<string, DataLevel> _configLevelDic = new Dictionary<string, DataLevel>();
|
|
|
|
|
|
public Dictionary<string, DataLevel> ConfigLevelDic => _configLevelDic;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private void LoadConfigLevel()
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
_cfg = TableManager.Instance.Tables.Level.DataMap.GetValueOrDefault(_id);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTask LoadData()
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
_levelData = await LevelUtils.LoadLevelData(_id);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTask LoadMap()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_levelData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_map != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
MapUtils.RemoveCameraController(CameraManager.Instance.MainCamera);
|
|
|
|
|
|
MapUtils.UnLoadMap(_map);
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
_map = await MapUtils.LoadMap(_levelData.mapName);
|
|
|
|
|
|
MapUtils.BindCameraController(CameraManager.Instance.MainCamera, _map);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTask LoadNpc()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_levelData != null && _map != null)
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
for (var i = 0; i < _levelData.npcInfos.Count; i++)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
var npcInfo = _levelData.npcInfos[i];
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: LT:临时处理,后续需要根据配置来
|
|
|
|
|
|
var teamId = ETroopsId.Enemy1;
|
|
|
|
|
|
var pos = _map.BlockPosition2WorldPosition(npcInfo.position);
|
2023-10-25 14:09:09 +08:00
|
|
|
|
var yaw = LevelUtils.SetCharaterToward(npcInfo.npcToward);
|
|
|
|
|
|
var character = await _characterManager.CreateNPC(npcInfo.id, teamId, npcInfo.level, pos, yaw);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
character.transData.pos = pos;
|
|
|
|
|
|
character.Node.SetPosition(pos);
|
|
|
|
|
|
character.runtimeData.characterLevelData = new CharacterLevelData()
|
|
|
|
|
|
{
|
|
|
|
|
|
AttachAIName = npcInfo.attachAIType,
|
|
|
|
|
|
AIName = npcInfo.aIType,
|
2023-10-19 15:00:19 +08:00
|
|
|
|
BornPosition = npcInfo.position,
|
2023-08-22 19:08:45 +08:00
|
|
|
|
NpcToward = npcInfo.npcToward,
|
2023-10-19 15:00:19 +08:00
|
|
|
|
PatrolInfos = npcInfo.patrolInfos
|
2023-08-22 19:08:45 +08:00
|
|
|
|
};
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
character.PrepareReady();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void BindMap(Map map)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (map != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_map = map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_map.MapData.name.Equals(_levelData.mapName))
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
DebugUtil.LogError("{0}.{1} Error:map name not match", GetType(),
|
|
|
|
|
|
System.Reflection.MethodBase.GetCurrentMethod()?.Name);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Update(float deltaTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_isPause)
|
|
|
|
|
|
{
|
|
|
|
|
|
_stateMachine.Update(deltaTime * _speed);
|
|
|
|
|
|
_characterManager.Update(deltaTime * _speed);
|
|
|
|
|
|
AIManager.Instance.Update(deltaTime * _speed);
|
|
|
|
|
|
SelecterView.Instance.Update(deltaTime * _speed);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 这里是 level system的初始化,不是 level 场景的初始化
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
AIManager.Instance.Init();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
_characterManager = new CharacterManager();
|
|
|
|
|
|
_characterManager.Init();
|
|
|
|
|
|
|
|
|
|
|
|
VehicleManager.CreateInstance();
|
|
|
|
|
|
GameUnitMapper.CreateInstance();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
SkillManager.CreateInstance();
|
|
|
|
|
|
BuffManager.CreateInstance();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
EmojiManager.CreateInstance();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Release()
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
EmojiManager.inst.Dispose();
|
|
|
|
|
|
VehicleManager.Inst.Dispose();
|
|
|
|
|
|
GameUnitMapper.Inst.Dispose();
|
|
|
|
|
|
|
|
|
|
|
|
SkillManager.instance.Dispose();
|
|
|
|
|
|
BuffManager.instance.Dispose();
|
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
_stateMachine?.ChangeState(null);
|
|
|
|
|
|
|
|
|
|
|
|
_characterManager.Dispose();
|
|
|
|
|
|
_characterManager = null;
|
|
|
|
|
|
AIManager.Instance.Release();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
EffectManager.instance.ClearPool();
|
|
|
|
|
|
ObjPoolManager.instance.Clear();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async UniTask Load()
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
LoadConfigLevel();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
await LoadData();
|
|
|
|
|
|
await LoadMap();
|
|
|
|
|
|
|
|
|
|
|
|
await _InitAfterLoadMap();
|
|
|
|
|
|
|
|
|
|
|
|
await LoadNpc();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
await _LoadOthers();
|
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
RegisterAllEvent();
|
2023-11-06 18:20:55 +08:00
|
|
|
|
InitRules();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
_stateMachine.ChangeState(new PrepareState(this));
|
|
|
|
|
|
SelecterView.Instance.Init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private async UniTask _LoadOthers()
|
|
|
|
|
|
{
|
|
|
|
|
|
AssetManager.Instance.PostPreload(Constants.TIREMARK_UNIT_PATH);
|
|
|
|
|
|
AssetManager.Instance.PostPreload(Constants.TIREMARK_MAT_PATH);
|
2023-10-25 13:59:08 +08:00
|
|
|
|
AssetManager.Instance.PostPreload(Constants.CHARACTER_SELECT_GROUND_GFX);
|
2023-10-27 13:59:26 +08:00
|
|
|
|
AssetManager.Instance.PostPreload(Constants.EMOJI_HEAD_MAT);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await AssetManager.Instance.WaitAllPreloads();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
private async UniTask _InitAfterLoadMap()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 加载后处理
|
|
|
|
|
|
await _LoadPostProcess();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
// 初始化GameUnitMapper
|
|
|
|
|
|
GameUnitMapper.Inst.Init();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
// 表情相关
|
|
|
|
|
|
AssetManager.Instance.PostPreload(Constants.EMOJI_PREFAB_PATH);
|
|
|
|
|
|
|
|
|
|
|
|
await AssetManager.Instance.WaitAllPreloads();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTask _LoadPostProcess()
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
// 加载shader
|
|
|
|
|
|
AssetManager.Instance.PostPreload(Constants.SHADER_OUTLINE_PATH1);
|
|
|
|
|
|
AssetManager.Instance.PostPreload(Constants.SHADER_OUTLINE_PATH1_1);
|
|
|
|
|
|
AssetManager.Instance.PostPreload(Constants.SHADER_OUTLINE_PATH2);
|
|
|
|
|
|
AssetManager.Instance.PostPreload(Constants.SHADER_OUTLINE_PATH3);
|
|
|
|
|
|
await AssetManager.Instance.WaitAllPreloads();
|
|
|
|
|
|
var loadObj =
|
|
|
|
|
|
await AssetManager.Instance.LoadAssetAsync<GameObject>(Constants.OUTLINE_POSTPROCESS_PATH);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
if (loadObj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Object.Instantiate(loadObj);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void BeginBattle()
|
|
|
|
|
|
{
|
|
|
|
|
|
_stateMachine.ChangeState(new BattleState(this));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsPreparing()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _stateMachine.GetCurrentState() is PrepareState;
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public bool IsInBattle()
|
|
|
|
|
|
{
|
|
|
|
|
|
return isInBattle;
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
|
public bool IsEnd()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _stateMachine.GetCurrentState() is EndState;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public UniTask Unload()
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
MapUtils.RemoveCameraController(CameraManager.Instance.MainCamera);
|
|
|
|
|
|
MapUtils.UnLoadMap(_map);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
UnRegisterAllEvent();
|
2023-11-06 18:20:55 +08:00
|
|
|
|
ReleaseRules();
|
2023-08-22 19:08:45 +08:00
|
|
|
|
SelecterView.Instance.Release();
|
|
|
|
|
|
return UniTask.NextFrame();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LevelData GetLevelData()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _levelData;
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private const string DescKey = "LevelDesc{0}";
|
|
|
|
|
|
private const string NameKey = "LevelName{0}";
|
|
|
|
|
|
|
|
|
|
|
|
public string GetLevelName()
|
|
|
|
|
|
{
|
|
|
|
|
|
return StringManager.Instance.GetLocalizeTextByKey(string.Format(NameKey, _id));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetLevelDesc(LevelData levelData)
|
|
|
|
|
|
{
|
|
|
|
|
|
return StringManager.Instance.GetLocalizeTextByKey(string.Format(DescKey, _id));
|
|
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2023-10-25 14:09:09 +08:00
|
|
|
|
}
|