862 lines
30 KiB
C#
862 lines
30 KiB
C#
using cfg.LevelCfg;
|
|
using System.Collections.Generic;
|
|
using AOT.PostProcess.BlackArea;
|
|
using Code.Scripts.Gameplay.Enviorment;
|
|
using Code.Scripts.Gameplay.Fight.Evacuate;
|
|
using Code.Scripts.Gameplay.Fight.ExtLogic;
|
|
using Code.Scripts.Gameplay.PlaneShadow;
|
|
using Code.Scripts.Gameplay.Utils;
|
|
//using CriWare;
|
|
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay.AI;
|
|
using Gameplay.Area;
|
|
using Gameplay.Area.Around;
|
|
using Gameplay.BT.Variables;
|
|
using Gameplay.Buff;
|
|
using Gameplay.Bullet;
|
|
using Gameplay.Character;
|
|
using Gameplay.Common;
|
|
using Gameplay.Effect;
|
|
using Gameplay.Emoji;
|
|
using Gameplay.Fight.Capture;
|
|
using Gameplay.Fight.FightStory;
|
|
using Gameplay.Fight.Flag;
|
|
using Gameplay.Level.FightInfo;
|
|
using Gameplay.Level.Select;
|
|
using Gameplay.Pause;
|
|
using Gameplay.Performance;
|
|
using Gameplay.Pool;
|
|
using Gameplay.PostProcess.BlackArea;
|
|
using Gameplay.Skill;
|
|
using Gameplay.SubSystems;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Utils;
|
|
using Gameplay.Vehicle.Impl;
|
|
using LTGame;
|
|
using PhxhSDK;
|
|
using SRF;
|
|
using UnityEngine;
|
|
using Utils.Bounds;
|
|
|
|
namespace Gameplay.Level
|
|
{
|
|
public partial class Level : IUpdatable, ILoadable
|
|
{
|
|
private int _id;
|
|
|
|
private LevelData _levelData;
|
|
private LevelInfo _currLevelInfo;
|
|
private Map _map;
|
|
|
|
private NStateMachine<BaseLevelState> _fsm = new NStateMachine<BaseLevelState>();
|
|
public bool isInBattle = false;
|
|
private object _param;
|
|
|
|
public int ID => _id;
|
|
public Map Map => _map;
|
|
|
|
public FightStoryManager fightStoryManager = new FightStoryManager();
|
|
public FightInfoManager fightInfoManager = new FightInfoManager();
|
|
|
|
public float LevelTime { set; get; }
|
|
|
|
public bool IsPvPLevel => _id == TableManager.Instance.Tables.GlobalConfig.PVPLevelID;
|
|
|
|
public bool IsWar => _currLevelInfo.ChapterInfo.Cfg.Type == E_ChapterType.War;
|
|
|
|
private List<string> _cacheLoadUrls = new List<string>();
|
|
|
|
/// <summary>
|
|
/// 上缴旗子数量
|
|
/// </summary>
|
|
public int FlagSubmit;
|
|
/// <summary>
|
|
/// 撤离数量
|
|
/// </summary>
|
|
public int RetreatCount;
|
|
/// <summary>
|
|
/// 己方Npc的LocalID
|
|
/// </summary>
|
|
public List<int> SelfNpcLocalID;
|
|
|
|
public Level(int leveId,
|
|
object param = null)
|
|
{
|
|
_id = leveId;
|
|
_param = param;
|
|
_Init();
|
|
}
|
|
|
|
private Dictionary<string, DataLevel> _configLevelDic = new Dictionary<string, DataLevel>();
|
|
public Dictionary<string, DataLevel> ConfigLevelDic => _configLevelDic;
|
|
|
|
private void LoadConfigLevel()
|
|
{
|
|
LevelManager.Instance.TryGetLevelInfoByID(_id, out _currLevelInfo);
|
|
}
|
|
|
|
private async UniTask LoadScene()
|
|
{
|
|
await GameSceneManager.Instance.LoadSceneAsync(_currLevelInfo.Cfg.LevelScene);
|
|
await AssetManager.Instance.LoadAndInstAsync(CmpAreaColorSettings.ASSET_PATH);
|
|
}
|
|
|
|
private async UniTask UnLoadScene()
|
|
{
|
|
await GameSceneManager.Instance.UnLoadSceneAsync(_currLevelInfo.Cfg.LevelScene);
|
|
AssetManager.Instance.Unload(CmpAreaColorSettings.ASSET_PATH);
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
_levelData = _currLevelInfo.LevelData;
|
|
}
|
|
|
|
private async UniTask LoadMap()
|
|
{
|
|
_map = await MapUtils.LoadMap(_currLevelInfo.MapData);
|
|
AroundHelper.Init();
|
|
|
|
var sceneCamera = NLDSceneManager.Instance.SceneCamera;
|
|
CameraManager.Instance.SwitchMainCamera(sceneCamera);
|
|
MapUtils.BindCameraController(NLDSceneManager.Instance.SceneCamera, _map);
|
|
}
|
|
|
|
private async UniTask _LoadNpc()
|
|
{
|
|
if (!IsPvPLevel)
|
|
{
|
|
await _LoadEnemyFromLevelData();
|
|
await _LoadSelfNpcFromLevelData();
|
|
// 2024-11-14 不在需要护送对象
|
|
// await _LoadBeProtectFromLevelData();
|
|
}
|
|
else
|
|
{
|
|
await _LoadNPCFromPVPData();
|
|
// await _TempCreateBuild(1007, 54);
|
|
}
|
|
}
|
|
|
|
private async UniTask<GameUnit> _CreateFightBuild(uint id)
|
|
{
|
|
var teamId = ETroopsId.Enemy;
|
|
var createUnit = await GameUnitManager.instance.PrepareBuild((int)id, teamId);
|
|
if (createUnit == null)
|
|
{
|
|
DebugUtil.LogError("创建建筑失败");
|
|
return null;
|
|
}
|
|
return createUnit;
|
|
}
|
|
|
|
private async UniTask<GameUnit> _TempCreateBuild(uint id, int cellIndex)
|
|
{
|
|
DebugUtil.LogG("临时创建建筑");
|
|
var tempBuildId = (int)id;//1005;
|
|
var teamId = ETroopsId.Enemy;
|
|
var createUnit = await GameUnitManager.instance.PrepareBuild(tempBuildId, teamId);
|
|
if (createUnit == null)
|
|
{
|
|
DebugUtil.LogError("创建建筑失败");
|
|
return null;
|
|
}
|
|
GameUnitManager.instance.MoveUnitToFight(createUnit.GetID(), cellIndex, 0);
|
|
return createUnit;
|
|
}
|
|
|
|
|
|
private async UniTask _LoadSelfNpcFromLevelData()
|
|
{
|
|
if (_levelData == null) return;
|
|
if (_map == null) return;
|
|
|
|
for (int i = 0; i < _levelData.selfNpcInfos.Count; i++)
|
|
{
|
|
var npcInfo = _levelData.selfNpcInfos[i];
|
|
|
|
var cellIndex = _map.BlockPosition2TGSCellIndex(npcInfo.position);
|
|
var yaw = LevelUtils.SetCharaterToward(npcInfo.npcToward);
|
|
var createUnit = await GameUnitManager.instance.PrepareSelfNpc(npcInfo);
|
|
if (createUnit == null)
|
|
{
|
|
DebugUtil.LogError("创建己方npc失败:" + npcInfo.id);
|
|
continue;
|
|
}
|
|
|
|
createUnit.unitLevelData = new UnitLevelData()
|
|
{
|
|
LocalId = npcInfo.index,
|
|
AttachAIName = npcInfo.attachAIType,
|
|
AIName = npcInfo.aIType,
|
|
BornPosition = cellIndex,
|
|
NpcToward = npcInfo.npcToward,
|
|
PatrolInfos = npcInfo.patrolInfos,
|
|
GroupInfos = npcInfo.groups,
|
|
DefensiveDistance = npcInfo.defensiveDistance,
|
|
monsterId = npcInfo.id,
|
|
AIConfigName = npcInfo.configName,
|
|
};
|
|
|
|
createUnit.transData.bornCellIndex = cellIndex;
|
|
GameUnitManager.instance.MoveUnitToFight(createUnit.GetID(), cellIndex, yaw);
|
|
}
|
|
}
|
|
|
|
private async UniTask _LoadEnemyFromLevelData()
|
|
{
|
|
if (_levelData == null) return;
|
|
if (_map == null) return;
|
|
for (var i = 0; i < _levelData.npcInfos.Count; i++)
|
|
{
|
|
var npcInfo = _levelData.npcInfos[i];
|
|
|
|
var cellIndex = _map.BlockPosition2TGSCellIndex(npcInfo.position);
|
|
var yaw = LevelUtils.SetCharaterToward(npcInfo.npcToward);
|
|
var createUnit =
|
|
await GameUnitManager.instance.PrepareEnemyNpc(npcInfo);
|
|
if (createUnit == null)
|
|
{
|
|
DebugUtil.LogError("创建敌人失败:" + npcInfo.id);
|
|
continue;
|
|
}
|
|
|
|
createUnit.unitLevelData = new UnitLevelData()
|
|
{
|
|
LocalId = npcInfo.index,
|
|
AttachAIName = npcInfo.attachAIType,
|
|
AIName = npcInfo.aIType,
|
|
BornPosition = cellIndex,
|
|
NpcToward = npcInfo.npcToward,
|
|
PatrolInfos = npcInfo.patrolInfos,
|
|
GroupInfos = npcInfo.groups,
|
|
DefensiveDistance = npcInfo.defensiveDistance,
|
|
monsterId = npcInfo.id,
|
|
AIConfigName = npcInfo.configName,
|
|
IsHideOnLoad = npcInfo.isHideOnLoad,
|
|
};
|
|
|
|
if(!npcInfo.isHideOnLoad)
|
|
{
|
|
createUnit.transData.bornCellIndex = cellIndex;
|
|
GameUnitManager.instance.MoveUnitToFight(createUnit.GetID(), cellIndex, yaw);
|
|
}
|
|
}
|
|
}
|
|
|
|
private async UniTask _LoadNPCFromPVPData()
|
|
{
|
|
var pvpDefenderData = _param as PVPDefenderData;
|
|
if (pvpDefenderData == null)
|
|
{
|
|
DebugUtil.LogError("pvp参数不合法!");
|
|
return;
|
|
}
|
|
|
|
PVPManager.Instance.InFightEnemyCount = pvpDefenderData.pvpRuntimeUnitInfos.Count;
|
|
for (var i = 0; i < pvpDefenderData.pvpRuntimeUnitInfos.Count; i++)
|
|
{
|
|
var pvpUnitData = pvpDefenderData.pvpRuntimeUnitInfos[i];
|
|
//var id = (uint)pvpUnitData.unitID;
|
|
|
|
var position = _map.TGSCellIndex2BlockPosition(pvpUnitData.cellIndex);
|
|
var teamId = ETroopsId.Enemy;
|
|
GameUnit unit = null;
|
|
switch (pvpUnitData.type)
|
|
{
|
|
case Framework.Wrapper.Unit.UnitType.Charactor:
|
|
var cInfo = new CharacterDataInfo();
|
|
cInfo.Refresh(pvpUnitData.characterInfo);
|
|
unit = await GameUnitManager.instance.PrepareCharacter(cInfo, teamId);
|
|
break;
|
|
case Framework.Wrapper.Unit.UnitType.Vehicle:
|
|
//todo VehicleCultivateData第二个参数
|
|
var vInfo = new VehicleCultivateData();
|
|
vInfo.Refresh(pvpUnitData.vehicleInfo);
|
|
unit = await GameUnitManager.instance.PrepareVehicle(vInfo, teamId);
|
|
break;
|
|
case Framework.Wrapper.Unit.UnitType.Building:
|
|
var bInfo = pvpUnitData.fightBuildingData;
|
|
unit = await _CreateFightBuild(bInfo.Uid);
|
|
break;
|
|
}
|
|
|
|
if (unit == null)
|
|
{
|
|
DebugUtil.LogError("创建pvp unit失败");
|
|
continue;
|
|
}
|
|
|
|
unit.unitLevelData = new UnitLevelData()
|
|
{
|
|
AttachAIName = pvpUnitData.attachAIType,
|
|
AIName = pvpUnitData.aiType,
|
|
BornPosition = pvpUnitData.cellIndex,
|
|
NpcToward = _levelData.pvpDefendToward,
|
|
PatrolInfos = new(),
|
|
GroupInfos = new (),
|
|
};
|
|
|
|
var yaw = LevelUtils.SetCharaterToward(_levelData.pvpDefendToward);
|
|
GameUnitManager.instance.MoveUnitToFight(unit.GetID(), pvpUnitData.cellIndex, yaw);
|
|
}
|
|
}
|
|
|
|
public void Update(float deltaTime)
|
|
{
|
|
_fsm.LogicUpdate(deltaTime * _speed);
|
|
selectView?.LogicUpdate();
|
|
PlaneShadowManager.instance.ViewUpdate();
|
|
|
|
if (!_isPause)
|
|
{
|
|
// AI驱动
|
|
AIManager.Instance.Update(deltaTime * _speed);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 这里是 level system的初始化,不是 level 场景的初始化
|
|
/// </summary>
|
|
private void _Init()
|
|
{
|
|
_InitFsm();
|
|
|
|
FlagSubmit = 0;
|
|
|
|
// 初始化速度
|
|
ELevelSpeed.Level_0 = TableManager.Instance.Tables.GlobalConfig.FightSpeedParams[0];
|
|
ELevelSpeed.Level_1 = TableManager.Instance.Tables.GlobalConfig.FightSpeedParams[1];
|
|
ELevelSpeed.Level_2 = TableManager.Instance.Tables.GlobalConfig.FightSpeedParams[2];
|
|
ELevelSpeed.Level_3 = TableManager.Instance.Tables.GlobalConfig.FightSpeedParams[3];
|
|
var defaultLevelSpeedIndex = TableManager.Instance.Tables.GlobalConfig.FightSpeedDefault;
|
|
ELevelSpeed.DEFAULT_SPEED = TableManager.Instance.Tables.GlobalConfig.FightSpeedParams[defaultLevelSpeedIndex];
|
|
|
|
AIManager.Instance.Init();
|
|
|
|
GameUnitManager.CreateInstance();
|
|
|
|
SkillManager.CreateInstance();
|
|
BuffManager.CreateInstance();
|
|
|
|
}
|
|
|
|
private void _InitFsm()
|
|
{
|
|
_fsm.Add(new LevelStatePreStory(this));
|
|
_fsm.Add(new LevelStatePrepare(this));
|
|
_fsm.Add(new LevelStateBattle(this));
|
|
_fsm.Add(new LevelStateBattleStory(this));
|
|
_fsm.Add(new LevelStateEnd(this));
|
|
_fsm.Add(new LevelStateEndStory(this));
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
_fsm.Exit();
|
|
|
|
fightInfoManager.Dispose();
|
|
|
|
BulletManager.instance.Dispose();
|
|
BoundsManager.instance.Dispose();
|
|
EnviormentManager.instance.Dispose();
|
|
|
|
AreaManager.instance.Dispose();
|
|
|
|
SkillManager.instance.Dispose();
|
|
BuffManager.instance.Dispose();
|
|
|
|
AIManager.Instance.Release();
|
|
|
|
CaptureManager.instance.Dispose();
|
|
FlagManager.instance.Dispose();
|
|
EvacuateManager.instance.Dispose();
|
|
|
|
// 在这里释放所有单位
|
|
GameUnitManager.instance.Dispose();
|
|
|
|
if (PauseManager.instance != null)
|
|
{
|
|
PauseManager.instance.Dispose();
|
|
}
|
|
|
|
EffectManager.instance.ClearPool();
|
|
ObjPoolManager.instance.Clear();
|
|
BlackAreaManager.instance.Dispose();
|
|
|
|
ExtLogicManager.instance.Dispose();
|
|
|
|
for (int i = 0; i < _cacheLoadUrls.Count; i++)
|
|
{
|
|
var url = _cacheLoadUrls[i];
|
|
AssetManager.Instance.Unload(url);
|
|
}
|
|
_cacheLoadUrls.Clear();
|
|
|
|
// 卸载关卡时强制隐藏技能相机
|
|
CameraManager.Instance.SkillCamera.gameObject.SetActive(false);
|
|
}
|
|
|
|
public async UniTask Load()
|
|
{
|
|
LoadConfigLevel();
|
|
|
|
// GameUnitManager.instance.PrepareUnits();
|
|
//UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_Loading); // 打开加载界面时已经移除
|
|
|
|
await LoadScene();
|
|
LoadData();
|
|
await LoadMap();
|
|
await _LoadWeather();
|
|
|
|
await _InitAfterLoadMap();
|
|
|
|
await _LoadOthers();
|
|
|
|
selectView = new SelectView();
|
|
selectView.Init();
|
|
|
|
PlaneShadowManager.instance.Init();
|
|
|
|
await _LoadNpc();
|
|
_CreateCapturePoints();
|
|
_CreateFlags();
|
|
_CreateEvacuate();
|
|
|
|
RegisterAllEvent();
|
|
InitRules();
|
|
_InitAudioListener();
|
|
|
|
_UpdateAllUnits();
|
|
|
|
InitAIStart();
|
|
|
|
_AfterLoadInit();
|
|
|
|
}
|
|
|
|
public void EnterLevel()
|
|
{
|
|
_fsm.SetForceChangeState(ELevelState.PreStory);
|
|
}
|
|
|
|
private void _AfterLoadInit()
|
|
{
|
|
ExtLogicManager.instance.Init();
|
|
|
|
AreaManager.instance.Init();
|
|
|
|
BulletManager.CreateInstance();
|
|
BuffManager.instance.Init();
|
|
SkillManager.instance.Init();
|
|
BulletManager.instance.Init();
|
|
|
|
PauseManager.CreateInstance();
|
|
PauseManager.instance.Init();
|
|
|
|
EnviormentManager.CreateInstance();
|
|
EnviormentManager.instance.Init();
|
|
|
|
var enableBlackArea = _currLevelInfo.Cfg.LevelTime == DayNightType.Night;
|
|
BlackAreaManager.instance.Init(enableBlackArea);
|
|
|
|
fightInfoManager.Init();
|
|
|
|
// 这个参数需要关闭
|
|
_map.TerrainGridSystem.respectOtherUI = false;
|
|
}
|
|
|
|
private void _InitAudioListener()
|
|
{
|
|
// var cameraRoot = CameraManager.Instance.MainCamera.gameObject;
|
|
// cameraRoot.RemoveComponentIfExists<CriAtomListener>();
|
|
// var rayHits = new RaycastHit[10];
|
|
// var ray = CameraManager.Instance.MainCamera.ScreenPointToRay(new Vector3(Screen.width / 2f,
|
|
// Screen.height / 2f, 0));
|
|
// var layerMask = LayerMask.GetMask("Ground");
|
|
// var rayHit = Physics.RaycastNonAlloc(ray, rayHits, 1000, layerMask);
|
|
// if (rayHit <= 0) return;
|
|
// var firstHit = rayHits[0];
|
|
// var hitPoint = firstHit.point;
|
|
// var listenerRoot = new GameObject("Listener");
|
|
// listenerRoot.transform.SetParent(cameraRoot.transform);
|
|
// listenerRoot.transform.position = hitPoint;
|
|
// listenerRoot.AddComponent<CriAtomListener>();
|
|
}
|
|
|
|
private void _UpdateAllUnits()
|
|
{
|
|
var units = GameUnitManager.instance.infightUnits.unitList;
|
|
for (int i = 0; i < units.Count; i++)
|
|
{
|
|
var unit = units[i];
|
|
unit.ForceUpdateBlackArea();
|
|
}
|
|
}
|
|
|
|
private async void InitAIStart()
|
|
{
|
|
SelfNpcLocalID = new List<int>();
|
|
var units = GameUnitManager.instance.infightUnits.unitList;
|
|
foreach (var unit in units)
|
|
{
|
|
if (unit is Character.Character unitCharacter)
|
|
{
|
|
await _HandleForCharacter(unitCharacter);
|
|
}
|
|
else if (unit is NormalVehicle unitVehicle)
|
|
{
|
|
await _HandleForVehicle(unitVehicle);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private async UniTask _HandleForVehicle(NormalVehicle vehicle)
|
|
{
|
|
if (vehicle == null) return;
|
|
|
|
if (vehicle.commonData.troopId == ETroopsId.Self)
|
|
{
|
|
if (vehicle.unitLevelData == null)
|
|
{
|
|
// 己方默认激活
|
|
vehicle.statusData.isAttackActive = true;
|
|
return;
|
|
}
|
|
|
|
SelfNpcLocalID.Add(vehicle.unitLevelData.LocalId);
|
|
}
|
|
else
|
|
{
|
|
// AI 默认非激活
|
|
vehicle.statusData.isAttackActive = false;
|
|
vehicle.statusData.isInFight = false;
|
|
}
|
|
|
|
var vehicleAIName = string.IsNullOrEmpty(vehicle.unitLevelData.AIConfigName)
|
|
? "AIBehavior"
|
|
: vehicle.unitLevelData.AIConfigName;
|
|
|
|
var bt = await AIManager.Instance.RegisterAI(vehicle.Node.GameObject, vehicleAIName);
|
|
bt.SetVariable("battleInfo", new SharedBattleInfo()
|
|
{
|
|
Value = new BattleInfo()
|
|
{
|
|
ownerID = vehicle.GetID(),
|
|
AIName = vehicle.unitLevelData.AIName,
|
|
AttachAIName = vehicle.unitLevelData.AttachAIName,
|
|
patrolInfos = vehicle.unitLevelData.PatrolInfos,
|
|
groupInfo = vehicle.unitLevelData.GroupInfos,
|
|
cannotReach = new List<int>(),
|
|
}
|
|
});
|
|
vehicle.statusData.isAIControll = false;
|
|
}
|
|
|
|
private async UniTask _HandleForCharacter(Character.Character character)
|
|
{
|
|
if (character == null) return;
|
|
|
|
if (character.troopId == ETroopsId.Self)
|
|
{
|
|
if (character.unitLevelData == null)
|
|
{
|
|
// 玩家默认激活
|
|
character.statusData.isAttackActive = true;
|
|
return;
|
|
}
|
|
|
|
SelfNpcLocalID.Add(character.unitLevelData.LocalId);
|
|
}
|
|
else
|
|
{
|
|
// AI 默认非激活
|
|
character.statusData.isAttackActive = false;
|
|
character.statusData.isInFight = false;
|
|
}
|
|
|
|
var characterAIName = string.IsNullOrEmpty(character.unitLevelData.AIConfigName)
|
|
? "AIBehavior"
|
|
: character.unitLevelData.AIConfigName;
|
|
|
|
var bt = await AIManager.Instance.RegisterAI(character.Node.GameObject, characterAIName);
|
|
bt.SetVariable("battleInfo", new SharedBattleInfo()
|
|
{
|
|
Value = new BattleInfo()
|
|
{
|
|
ownerID = character.GetID(),
|
|
AIName = character.unitLevelData.AIName,
|
|
AttachAIName = character.unitLevelData.AttachAIName,
|
|
patrolInfos = character.unitLevelData.PatrolInfos,
|
|
groupInfo = character.unitLevelData.GroupInfos,
|
|
cannotReach = new List<int>(),
|
|
}
|
|
});
|
|
|
|
if(character.unitLevelData.AttachAIName == LevelData.AttachAIType.None)
|
|
character.statusData.isAttackActive = true;
|
|
character.statusData.isAIControll = false;
|
|
}
|
|
|
|
private void _CreateCapturePoints()
|
|
{
|
|
CaptureManager.CreateInstance();
|
|
CaptureManager.instance.Init();
|
|
}
|
|
|
|
private void _CreateFlags()
|
|
{
|
|
FlagManager.CreateInstance();
|
|
FlagManager.instance.Init();
|
|
}
|
|
|
|
private void _CreateEvacuate()
|
|
{
|
|
EvacuateManager.CreateInstance();
|
|
EvacuateManager.instance.Init();
|
|
}
|
|
|
|
private async UniTask _LoadWeather()
|
|
{
|
|
var weatherType = (int)_currLevelInfo.Cfg.LevelWeather;
|
|
var groundType = (int)_currLevelInfo.eLevelTerrain;
|
|
var weatherEffectConfig = TableManager.Instance.Tables.WeatherEffectConfig.Get(weatherType, groundType);
|
|
if (weatherEffectConfig == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var cameraPrefab = weatherEffectConfig.CameraPrefab;
|
|
if (string.IsNullOrEmpty(cameraPrefab))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var finalPath = PathEx.GetWeatherCameraEffectPath(cameraPrefab);
|
|
var loadObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(finalPath);
|
|
if (loadObj == null)
|
|
{
|
|
DebugUtil.LogError("加载天气特效失败:{0}", finalPath);
|
|
return;
|
|
}
|
|
|
|
var cameraObj = CameraManager.Instance.MainCamera.gameObject;
|
|
var weatherCamera = Object.Instantiate(loadObj, cameraObj.transform);
|
|
weatherCamera.transform.localPosition = Vector3.zero;
|
|
weatherCamera.transform.localRotation = Quaternion.identity;
|
|
}
|
|
|
|
private void _SetShadowDistance()
|
|
{
|
|
var setDistance = _currLevelInfo.Cfg.ShadowDistance;
|
|
ShadowEx.SetShadowDistance(setDistance);
|
|
}
|
|
|
|
private void _PostPreload(string url)
|
|
{
|
|
AssetManager.Instance.PostPreload(url);
|
|
_cacheLoadUrls.Add(url);
|
|
}
|
|
|
|
private async UniTask _LoadOthers()
|
|
{
|
|
_PostPreload(PathDefine.TireMark.TIREMARK_UNIT_PATH);
|
|
_PostPreload(PathDefine.TireMark.TIREMARK_MAT_PATH);
|
|
_PostPreload(PathDefine.SelectView.CHARACTER_SELECT_GROUND_GFX);
|
|
_PostPreload(PathDefine.Summon.SELF);
|
|
_PostPreload(PathDefine.Summon.ENEMY);
|
|
_PostPreload(PathDefine.SkillArea.SKILL_GORUND_HIGH_LIGHT);
|
|
_PostPreload(PathDefine.SkillArea.HIGHLIGHT_POINT);
|
|
|
|
// 占领相关
|
|
_PostPreload(PathDefine.CapturePoint.CAPTURE_POINT_PROGRESS_PATH);
|
|
_PostPreload(PathDefine.CapturePoint.CAPTURE_POINT_GROUND_POINT_PATH);
|
|
|
|
// 扛旗相关
|
|
_PostPreload(PathDefine.HoldFlag.FLAG_RETURN_PATH);
|
|
_PostPreload(PathDefine.HoldFlag.FLAG_GROUND_POINT_PATH);
|
|
|
|
_PostPreload(PathDefine.ProtectUnit.TARGET_POINT_PATH);
|
|
_PostPreload(PathDefine.BlackArea.FIGHT_LIGHT_AREA_PATH);
|
|
_PostPreload(PathDefine.AttackArea.FIGHT_CELL_COLLIDER_PATH);
|
|
_PostPreload(SkillRotateCamera.PREFAB_PATH);
|
|
_PostPreload(BlackAreaManagerImpl.BLIT_MAT_PATH);
|
|
_PostPreload(PathDefine.MoveArea.MOVE_AREA_POINT_PATH);
|
|
|
|
for (int i = 0; i < PathDefine.RoadLine.END_NOTICES.Length; i++)
|
|
{
|
|
var path = PathDefine.RoadLine.END_NOTICES[i];
|
|
_PostPreload(path);
|
|
}
|
|
_PostPreload(PathDefine.RoadLine.ROAD_LINE);
|
|
_PostPreload(PathDefine.RoadLine.ROAD_LINE_STRAIGHT);
|
|
|
|
_PostPreload(PathDefine.ReadyArea.READY_AREA_POINT);
|
|
|
|
_PostPreload(PathDefine.SkillArea.SELECT_POINT);
|
|
|
|
// 撤离相关
|
|
_PostPreload(PathDefine.Evacuate.EVACUATE_LOOP_EFFECT_PATH);
|
|
_PostPreload(PathDefine.Evacuate.EVACUATE_GROUND_POINT_PATH);
|
|
|
|
// 面片阴影
|
|
_PostPreload(PathDefine.PlaneShadow.PLANE_SHADOW_VEHICLE_PATH);
|
|
_PostPreload(PathDefine.PlaneShadow.PLANE_SHADOW_CHARACTER_PATH);
|
|
|
|
// 六边形边
|
|
_PostPreload(PathDefine.BoardSide.SIDE_PATHS[0]);
|
|
_PostPreload(PathDefine.BoardSide.SIDE_PATHS[1]);
|
|
_PostPreload(PathDefine.BoardSide.SIDE_PATHS[2]);
|
|
_PostPreload(PathDefine.BoardSide.SIDE_PATHS[3]);
|
|
_PostPreload(PathDefine.BoardSide.SIDE_PATHS[4]);
|
|
_PostPreload(PathDefine.BoardSide.SIDE_PATHS[5]);
|
|
|
|
await AssetManager.Instance.WaitAllPreloads();
|
|
}
|
|
|
|
private async UniTask _InitAfterLoadMap()
|
|
{
|
|
// 设置为手动更新
|
|
Physics.simulationMode = SimulationMode.Script;
|
|
Physics2D.simulationMode = SimulationMode2D.Script;
|
|
|
|
// 更新地面
|
|
Physics.SyncTransforms();
|
|
|
|
// 设置TGS为运行半透明地面
|
|
_map.TerrainGridSystem.transparentBackground = true;
|
|
|
|
var blackAreaInst = new BlackAreaManagerImpl();
|
|
BlackAreaManager.CreateInstance(blackAreaInst);
|
|
|
|
_InitCameraParams();
|
|
|
|
// 加载后处理
|
|
await _LoadOutlinePost();
|
|
|
|
AreaManager.CreateInstance();
|
|
|
|
_InitPerformanceSetting();
|
|
|
|
await AssetManager.Instance.WaitAllPreloads();
|
|
}
|
|
|
|
private void _InitCameraParams()
|
|
{
|
|
var camera = CameraManager.Instance.MainCamera;
|
|
var cullingMask = 1 << LayerDefine.Default
|
|
| 1 << LayerDefine.GROUND
|
|
| 1 << LayerDefine.UNIT
|
|
| 1 << LayerDefine.Skill
|
|
| 1 << LayerDefine.LightArea
|
|
| 1 << LayerDefine.TeamSelf
|
|
| 1 << LayerDefine.TeamEnemy;
|
|
camera.cullingMask = cullingMask;
|
|
}
|
|
|
|
private void _InitPerformanceSetting()
|
|
{
|
|
PerformanceManager.instance.AutoSetGlobalVolume();
|
|
_SetShadowDistance();
|
|
}
|
|
|
|
private async UniTask _LoadOutlinePost()
|
|
{
|
|
// todo: 因为逻辑上有使用outlinemanager.instance 所以这里需要先加载
|
|
// if (!PerformanceManager.instance.data.enablePostOutline) return;
|
|
// 加载shader
|
|
_PostPreload(PathDefine.Outline.MAT1);
|
|
_PostPreload(PathDefine.Outline.MAT1_1);
|
|
_PostPreload(PathDefine.Outline.MAT2);
|
|
_PostPreload(PathDefine.Outline.MAT3);
|
|
await AssetManager.Instance.WaitAllPreloads();
|
|
var loadObj =
|
|
await AssetManager.Instance.LoadAssetAsync<GameObject>(PathDefine.Outline.MANAGER_PATH);
|
|
if (loadObj != null)
|
|
{
|
|
Object.Instantiate(loadObj);
|
|
|
|
OutlineManager.instance.mat1 = AssetManager.Instance.GetPreLoadResult<Material>(PathDefine.Outline.MAT1);
|
|
OutlineManager.instance.mat1_1 = AssetManager.Instance.GetPreLoadResult<Material>(PathDefine.Outline.MAT1_1);
|
|
OutlineManager.instance.mat2 = AssetManager.Instance.GetPreLoadResult<Material>(PathDefine.Outline.MAT2);
|
|
OutlineManager.instance.mat3 = AssetManager.Instance.GetPreLoadResult<Material>(PathDefine.Outline.MAT3);
|
|
|
|
// 全部instance之后再设置
|
|
OutlineManager.instance.mat1 = new Material(OutlineManager.instance.mat1);
|
|
OutlineManager.instance.mat1_1 = new Material(OutlineManager.instance.mat1_1);
|
|
OutlineManager.instance.mat2 = new Material(OutlineManager.instance.mat2);
|
|
OutlineManager.instance.mat3 = new Material(OutlineManager.instance.mat3);
|
|
|
|
OutlineManager.instance.targetCamera = CameraManager.Instance.MainCamera;
|
|
|
|
var screenWidth = Screen.width;
|
|
var sampleDistance = OutlineManager.instance.m_SampleDistance;
|
|
var wrapDistance = sampleDistance / 1080 * screenWidth;
|
|
var scaleProgress = CameraManager.Instance.GetOutlineScale(wrapDistance);
|
|
OutlineManager.instance.scaleProgress = scaleProgress;
|
|
}
|
|
}
|
|
|
|
public async void BeginBattle()
|
|
{
|
|
_fsm.SetForceChangeState(ELevelState.Battle);
|
|
// 延迟激活AI
|
|
await UniTask.Delay(500);
|
|
AIManager.Instance.StartAI();
|
|
}
|
|
|
|
public bool IsPreparing()
|
|
{
|
|
if (_fsm.currentState == null)
|
|
{
|
|
return false;
|
|
}
|
|
return _fsm.currentState.id == ELevelState.Prepare;
|
|
}
|
|
|
|
public bool IsInBattle()
|
|
{
|
|
return isInBattle;
|
|
}
|
|
|
|
public bool IsEnd()
|
|
{
|
|
if (_fsm.currentState == null)
|
|
{
|
|
return false;
|
|
}
|
|
return _fsm.currentState.id == ELevelState.End;
|
|
}
|
|
|
|
public void ClickFromScreen(Vector2 screenPos)
|
|
{
|
|
var state = _fsm.currentState as BaseLevelState;
|
|
state?.ClickFromScreen(screenPos);
|
|
}
|
|
|
|
public async UniTask Unload()
|
|
{
|
|
CameraManager.Instance.RevertMainCamera();
|
|
MapUtils.UnLoadMap(_map);
|
|
UnRegisterAllEvent();
|
|
ReleaseRules();
|
|
selectView.Dispose();
|
|
PlaneShadowManager.instance.Dispose();
|
|
|
|
await UnLoadScene();
|
|
await UniTask.NextFrame();
|
|
}
|
|
|
|
public LevelData GetLevelData()
|
|
{
|
|
return _levelData;
|
|
}
|
|
|
|
public LevelInfo GetLevelInfo()
|
|
{
|
|
return _currLevelInfo;
|
|
}
|
|
}
|
|
} |