95 lines
3.0 KiB
C#
95 lines
3.0 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Area;
|
|
using Gameplay.Buff;
|
|
using Gameplay.Building.Data;
|
|
using Gameplay.Character;
|
|
using Gameplay.Performance;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
namespace Gameplay.Building
|
|
{
|
|
public abstract class UnitBuild : GameUnit
|
|
{
|
|
|
|
public EFightBuildType buildType { get; private set; } = EFightBuildType.None;
|
|
|
|
public BuildConfigData configData { get; private set; }
|
|
|
|
public UnitBuild(uint id,
|
|
int troopId) : base(id, troopId, EGameUnitType.Building)
|
|
{
|
|
}
|
|
|
|
public void InitConfig(BuildConfigData setConfig)
|
|
{
|
|
configData = setConfig;
|
|
buildType = configData.buildType;
|
|
statusData.canBeAttack = configData.rawConfig.Hp > 0;
|
|
|
|
if (statusData.canBeAttack)
|
|
{
|
|
aliveData.maxHp = configData.rawConfig.Hp;
|
|
aliveData.currentHp = aliveData.maxHp;
|
|
}
|
|
|
|
commonData.standLevel = configData.rawConfig.StandCrossLevel;
|
|
}
|
|
|
|
public async UniTask CreateAsync()
|
|
{
|
|
var modelPath = configData.rawConfig.ModelPath;
|
|
GameUnitManager.instance.RecordLoadPath(modelPath);
|
|
var sampleObj = await AssetManager.Instance.LoadAssetAsync<GameObject>(modelPath);
|
|
if (sampleObj == null)
|
|
{
|
|
DebugUtil.LogError("加载建筑失败: {0}", modelPath);
|
|
return;
|
|
}
|
|
// 父节点已销毁
|
|
if (Node == null) return;
|
|
|
|
// 创建对象
|
|
var parent = Node.GameObject.transform;
|
|
var go = Object.Instantiate(sampleObj, parent, true);
|
|
go.transform.ResetLocals();
|
|
Node.GameObject.SetLayerEx(Node.GameObject.layer);
|
|
|
|
// 设置后处理
|
|
var obj = Node.GameObject;
|
|
var isEnemy = commonData.troopId != ETroopsId.Self;
|
|
OutlineManager.instance.AutoAddFromObj(obj, isEnemy);
|
|
|
|
PerformanceManager.instance.HandleCreateUnit(obj);
|
|
}
|
|
|
|
protected override void _OnEnterBattle()
|
|
{
|
|
base._OnEnterBattle();
|
|
isReady = true;
|
|
BuffManager.instance.InitBuild(this);
|
|
buffManager.TriggerEnterBattle();
|
|
|
|
if (configData.rawConfig.BlockAttack)
|
|
{
|
|
var blockData = AreaManager.instance.attackAreaManager.CreateBlockAttackCell(transData.cellIndex);
|
|
blockData.canBeAttack = statusData.canBeAttack;
|
|
}
|
|
}
|
|
|
|
protected override void _OnExitBattle()
|
|
{
|
|
base._OnExitBattle();
|
|
isReady = false;
|
|
buffManager?.TriggerExitBattle();
|
|
|
|
if (configData.rawConfig.BlockAttack)
|
|
{
|
|
AreaManager.instance.attackAreaManager.RemoveBlockAttackCell(transData.cellIndex);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|