using Animancer; using DG.Tweening; using ET.FUIBattle; using UnityEngine; using UnityEngine.EventSystems; namespace ET { public class BattleUnitViewComponentAwakeSystem : AwakeSystem { public override void Awake(BattleUnitViewComponent self) { self.Awake(); } } public class BattleUnitViewComponentDestroySystem : DestroySystem { public override void Destroy(BattleUnitViewComponent self) { self.Destroy(); } } public static class BattleAnimName { public const string Idle = "Battle_Idle"; public const string Run = "Battle_Run"; public const string Attack = "Battle_Attack"; public const string BeHit = "BeHit"; } [FriendClass(typeof(BattleUnitViewComponent))] [FriendClass(typeof(BattleSceneViewComponent))] [FriendClass(typeof(Fighter))] public static class BattleUnitViewComponentSystem { public static void Awake(this BattleUnitViewComponent self) { self.Fighter = self.GetParent(); } public static void Init(this BattleUnitViewComponent self, int index, bool left) { var battleSceneView = self.ZoneScene().CurrentScene().GetComponent(); GameObject peopleGO = self.InstantiateSync("People_1001", battleSceneView.PeopleRoot); self.DisplayGameObject = peopleGO; ReferenceCollector rc = peopleGO.GetComponent(); self.ThrowPoint = rc.Get("bone_12").transform; var pos = battleSceneView.GetUnitPosByIndex(index, left); peopleGO.transform.position = pos; self.Index = index; self.Left = left; if (!left) { var scale = peopleGO.transform.localScale; peopleGO.transform.localScale = new Vector3(-scale.x, scale.y, scale.z); } var model = self.DisplayGameObject.transform.Find("Body/Model"); self.AnimancerComp = model.GetComponent(); self.AnimancerComp.TryPlay(BattleAnimName.Idle); self.SEventReceiver = model.GetComponent(); // init click event EventTrigger trigger = self.DisplayGameObject.transform.Find("SpriteClick").GetComponent(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener((data) => { self.OnSpriteClicked(); }); trigger.triggers.Add(entry); } public static void OnSpriteClicked(this BattleUnitViewComponent self) { Log.Info(self.Index.ToString()); var fuiBattleMain = (FUIBattleMainComponent)self.ZoneScene().GetComponent().GetUI(FUI_BattleMain.UIResName); fuiBattleMain.ShowBuffDesc(FUIHelper.ConvertToUIPos(self.GetTopPos())); } public static Vector3 GetTopPos(this BattleUnitViewComponent self) { return self.DisplayGameObject.transform.position + Vector3.up * 2; } public static void BeHit(this BattleUnitViewComponent self) { var prefab = YooAssetComponent.Instance.LoadAssetSync("Hit_Blood"); GameObject fxGO = Util.GameObjectPoolHelper.SpawnGameObject(prefab); fxGO.transform.position = self.DisplayGameObject.transform.position + Vector3.up; ParticleController pc = fxGO.GetComponent(); pc.Play(); pc.OnParticleEnd = () => { Util.GameObjectPoolHelper.ReturnObjectToPool(fxGO); }; var state = self.AnimancerComp.TryPlay(BattleAnimName.BeHit); // state.Events.OnEnd = () => // { // self.AnimancerComp.TryPlay(BattleAnimName.Idle); // }; state.Events.endEvent = new AnimancerEvent(1.0f, () => { self.AnimancerComp.TryPlay(BattleAnimName.Idle); }); } public static void CheckState(this BattleUnitViewComponent self) { if (!self.Fighter.IsAlive) { var sprs = self.DisplayGameObject.transform.GetComponentsInChildren(); foreach (SpriteRenderer spriteRenderer in sprs) { spriteRenderer.color = Color.black; } } } public static void ShowStateMsg(this BattleUnitViewComponent self, string msg) { var fuiComp = self.ZoneScene().GetComponent(); var battleComp = fuiComp.GetUI(FUI_BattleMain.UIResName) as FUIBattleMainComponent; battleComp.UpdateUnitStateInfo(self.Fighter, msg); } // 是否需要移动到目标前去攻击 public static bool NeedMoveToAttack(this BattleUnitViewComponent self) { return false; } public static void Destroy(this BattleUnitViewComponent self) { if (self.Parent == null) { return; } GameObject.Destroy(self.DisplayGameObject); } } }