123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- 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<CombatHeroEntity> Init(CombatAIBasic combatAIBasic, CombatHeroInfo combatHeroInfo,
- System.Action<CombatHeroEntity> callBack = null)
- {
- //后面记到检查战斗里面不要出现异步加载,也不要出现同步IO加载
-
- GameObjectPool poolInterface =
- await GObjectPool.Instance.FetchAsync<GameObjectPool>(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<TextAsset>(combatHeroInfo.modelName + "_TD.txt");
- TextAsset textAsset = assetHandle.AssetObject<TextAsset>();
- TimeLienData timeLienData = JsonManager.FromJson<TimeLienData>(textAsset.text);
- timeLienData.DeserializeData();
- assetHandle.Release();
- combatHeroTimeLineControl = new CombatHeroTimeLineControl();
- combatHeroTimeLineControl.Init(timeLienData);
- combatHeroGameObject = new CombatHeroGameObject();
- combatHeroGameObject.Init(this, poolInterface);
- NavMeshAgent navMeshAgent = poolInterface.own.GetComponent<NavMeshAgent>();
- if (combatAIBasic == null)
- {
- combatAIBasic = new CombatAIBasic();
- }
- HeroEntityMono heroEntityMono = poolInterface.own.GetComponent<HeroEntityMono>();
- if (heroEntityMono == null)
- {
- heroEntityMono = poolInterface.own.AddComponent<HeroEntityMono>();
- }
- 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<AnimancerComponent>();
- 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<T>()
- {
- return (T)(object)this;
- }
- public T GetILifetCycleHitPoint<T>(string hitPoinName, bool isStandType, bool isIgnoreHind)
- where T : ILifetCycleHitPoint
- {
- return combatHeroGameObject.GetILifetCycleHitPoint<T>(hitPoinName, isStandType, isIgnoreHind);
- }
- public T GetMainHotPoin<T>(bool isIgnoreHind = false) where T : ILifetCycleHitPoint
- {
- return combatHeroGameObject.GetMainHotPoin<T>(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<CombatHeroHitPoint>(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();
- }
- }
|