using System.Collections.Generic; using Cysharp.Threading.Tasks; using Gameplay.Area; using Gameplay.Buff; using Gameplay.Character; using Gameplay.Fight.Protect.Anim; using Gameplay.Fight.Protect.Data; using Gameplay.Fight.Protect.State; using Gameplay.Performance; using Gameplay.Skill; using Gameplay.Unit; using Gameplay.Unit.Data; using LTGame; using PhxhSDK; using UnityEngine; namespace Gameplay.Fight.Protect { public class BeProtectUnit : GameUnit { public BeProtectDataConfig configData; public BeProtectUnitAnim anim; private NStateMachine _fsm; public List pathCellIndexs; public List displayPath; public int currentMoveIndex; private BeProtectTargetPoint _targetPoint; public BeProtectUnit(uint id, int troopId, BeProtectDataConfig configData) : base(id, troopId, EGameUnitType.BeProtect) { this.configData = configData; if (this.configData == null) { DebugUtil.LogError("BeProtectUnit配置为空"); return; } debugShowInfo = new DebugShowInfo(); debugShowInfo.name = configData.rawConfig.Name; debugShowInfo.configId = "ProtectUnitConfig@" + configData.rawConfig.ID; debugShowInfo.iconPath = ""; commonData.canControl = false; commonData.standLevel = configData.rawConfig.StandCrossLevel; commonData.crossLevel = configData.rawConfig.MoveCrossLevel; pathCellIndexs = new List(); displayPath = new List(); } public void CreateTargetPoint(int targetIndex) { controlData.targetCellIndex = targetIndex; _targetPoint = new BeProtectTargetPoint(targetIndex); } private void _InitFsm() { _fsm = new NStateMachine(); _fsm.Add(new BeProtectStateIdle(this)); _fsm.Add(new BeProtectStateMove(this)); _fsm.Add(new BeProtectStateDead(this)); _fsm.Add(new BeProtectStateFindPath(this)); _fsm.Add(new BeProtectStateFinish(this)); } public async UniTask CreateAsync() { GameUnitManager.instance.RecordLoadPath(configData.modelPath); var sampleObj = await AssetManager.Instance.LoadAssetAsync(configData.modelPath); if (sampleObj == null) { DebugUtil.LogError("加载BeProtectUnit失败: {0}", configData.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); anim = new BeProtectUnitAnim(go); // 设置后处理 var obj = Node.GameObject; var isEnemy = commonData.troopId != ETroopsId.Self; OutlineManager.instance.AutoAddFromObj(obj, isEnemy); PerformanceManager.instance.HandleCreateUnit(obj); } protected override async UniTask _OnPrepare() { _InitFsm(); _InitProps(); BuffManager.instance.InitBeProtectUnit(this); } protected override void _OnEnterBattle() { base._OnEnterBattle(); isReady = true; _fsm.ChangeState(EBeProtectState.FindPath); AreaManager.instance.RegistBeProtectUnit(this); } private void _InitProps() { aliveData.maxHp = configData.rawConfig.HP; aliveData.maxMorale = 0; aliveData.maxShield = configData.rawConfig.Shield; aliveData.Init(true); fightData.moveSpeed = configData.rawConfig.MoveSpeed; fightData.turnSpeed = configData.rawConfig.TurnSpeed; } protected override void _OnLogicUpdate(float dt) { if (SkillManager.instance.needSkillPaused && SkillManager.instance.inSkillingUnit != this) { return; } _fsm.LogicUpdate(dt); _ViewUpdate(dt); } private void _ViewUpdate(float dt) { if (Node?.GameObject == null) return; // 更新trans if (transData.isTransChanged) { Node.GameObject.transform.SetPositionAndRotation(transData.pos, transData.rot); } transData.Reset(); anim.ViewUpdate(dt); } } }