using System.Collections; using System.Collections.Generic; using Animancer; using Common.Utility.CombatEvent; using Fort23.Core; using Fort23.UTool; using GameLogic.Combat.CombatTool; using GameLogic.Combat.Hero; using UnityEngine; using UnityEngine.AI; using UnityEngine.Rendering; using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface; public class CombatHeroEntity : ITimeLineSpecialDotPos, ILifeCycle, ITimeLineAnimtion, ITimeLineGetAttSpeed { public bool IsEnemy; public bool isDie; public int number; public CombatAIBasic CombatAIBasic; public CombatHeroGameObject combatHeroGameObject; public CombatHeroInfo CurrCombatHeroInfo; public CombatHeroInfo MaxCombatHeroInfo; public CombatHeroTimeLineControl combatHeroTimeLineControl; public CombatHeroAnimtion combatHeroAnimtion; public CombatHeroSkillControl CombatHeroSkillControl; public bool isFollowState; public Vector3 dotPos { get { return combatHeroGameObject.position; } } public Vector3 faceDir { get; } public async CTask Init(CombatAIBasic combatAIBasic, CombatHeroInfo combatHeroInfo, System.Action callBack = null) { //后面记到检查战斗里面不要出现异步加载,也不要出现同步IO加载 GameObjectPool poolInterface = await GObjectPool.Instance.FetchAsync(combatHeroInfo.modelName + ".prefab", null); #if !COMBAT_SERVER if (poolInterface == null || poolInterface.own == null) { return null; } poolInterface.own.SetActive(false); AssetHandle assetHandle = await AssetBundleLoadManager.Instance.LoadAssetAsyncTask(combatHeroInfo.modelName + "_TD.txt"); TextAsset textAsset = assetHandle.AssetObject(); TimeLienData timeLienData = JsonManager.FromJson(textAsset.text); timeLienData.DeserializeData(); assetHandle.Release(); combatHeroTimeLineControl = new CombatHeroTimeLineControl(); combatHeroTimeLineControl.Init(timeLienData); combatHeroGameObject = new CombatHeroGameObject(); combatHeroGameObject.Init(this, poolInterface); NavMeshAgent navMeshAgent = poolInterface.own.GetComponent(); if (combatAIBasic == null) { combatAIBasic = new CombatAIBasic(); } HeroEntityMono heroEntityMono = poolInterface.own.GetComponent(); if (heroEntityMono == null) { heroEntityMono = poolInterface.own.AddComponent(); } heroEntityMono.combatHeroEntity = this; CombatAIBasic = combatAIBasic; CombatAIBasic.Init(this, navMeshAgent); CurrCombatHeroInfo = combatHeroInfo.Copy(); MaxCombatHeroInfo = combatHeroInfo.Copy(); CombatHeroSkillControl = new CombatHeroSkillControl(); CombatHeroSkillControl.Init(this); AnimancerComponent animancerComponent = poolInterface.own.GetComponent(); combatHeroAnimtion = new CombatHeroAnimtion(); combatHeroAnimtion.Init(animancerComponent, this); CombatAIBasic.ChangeState(CombatHeroStateType.idle); CreateHeroHpEventData createHeroHpEventData = CreateHeroHpEventData.Create(); createHeroHpEventData.combatHeroEntity = this; EventManager.Instance.Dispatch(CustomEventType.CreateHeroHp, createHeroHpEventData); poolInterface.own.SetActive(true); callBack?.Invoke(this); #endif return this; } public void Update(float t) { CombatAIBasic.Update(t); CombatHeroSkillControl.Update(t); combatHeroTimeLineControl.Update(t); } public T This() { return (T)(object)this; } public T GetILifetCycleHitPoint(string hitPoinName, bool isStandType, bool isIgnoreHind) where T : ILifetCycleHitPoint { return combatHeroGameObject.GetILifetCycleHitPoint(hitPoinName, isStandType, isIgnoreHind); } public T GetMainHotPoin(bool isIgnoreHind = false) where T : ILifetCycleHitPoint { return combatHeroGameObject.GetMainHotPoin(isIgnoreHind); } public void PlayAnim(string animName, bool isLoop, int layerId, bool repeat, float speed) { combatHeroAnimtion.Play(animName, speed); } public SpecialDotInfo GetSpecialDotInfo(string specialDotName) { return combatHeroGameObject.GetMainHotPoin(false).GetSpecialDotInfo(specialDotName); } public float GetAttSpeed() { return CombatHeroSkillControl.NormalAttSpeedScale; } public void HeroDie(HarmReturnInfo harmReturnInfo) { isDie = true; HeroDieEventData heroDieEventData = HeroDieEventData.Create(); heroDieEventData.combatHeroEntity = this; heroDieEventData.HarmReturnInfo = harmReturnInfo; CombatEventManager.Instance.Dispatch(CombatEventType.HeroDie, heroDieEventData); combatHeroGameObject.HeroDie(); CombatAIBasic.ChangeState(CombatHeroStateType.dile); } public void HeroHurt(HarmReturnInfo harmReturnInfo) { CurrCombatHeroInfo.hp -= harmReturnInfo.att; HarmUpdateEventData harmUpdateEventData = HarmUpdateEventData.Create(); harmUpdateEventData.HarmReturnInfo = harmReturnInfo; CombatEventManager.Instance.Dispatch(CombatEventType.HarmUpdate, harmUpdateEventData); HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create(); heroHpUpdateEventData.combatHeroEntity = this; CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData); if (CurrCombatHeroInfo.hp <= 0) { HeroDie(harmReturnInfo); } } public void Dispose() { CombatHeroSkillControl.Dispose(); combatHeroGameObject.Dispose(); CombatAIBasic.Dispose(); combatHeroTimeLineControl.Dispose(); combatHeroAnimtion.Dispose(); } }