using Cal.DataTable; using ET; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace ET { public class UnitViewAwakeSystem: AwakeSystem { public override void Awake(UnitView self, GameObject gameObject) { self.Awake(gameObject); } } public class UnitViewDestroySystem: DestroySystem { public override void Destroy(UnitView self) { ResourceViewHelper.DestoryPrefabAsync(self.gameObject); self.gameObject = null; self.transform = null; self.spriteRenderer = null; self.monoAnimancer = null; self.HeadPoint = null; self.FootPoint = null; self.footEffect = null; } } public static class UnitViewSystem { public static void Awake(this UnitView self, GameObject gameObject) { Unit unit = self.unit = self.GetParent(); self.gameObject = gameObject; self.transform = gameObject.transform; self.spriteRenderer = gameObject.GetComponent(); self.monoAnimancer = gameObject.GetComponent(); if (self.monoAnimancer && self.monoAnimancer.Animator == null) self.monoAnimancer.Animator = gameObject.GetComponentInChildren(); gameObject.GetOrAddComponent().Component = self; var children = gameObject.GetComponentsInChildren(); foreach (Transform item in children) { switch (item.name) { case "HeadBarPoint": self.HeadPoint = item; break; case "FootPoint": self.FootPoint = item; break; } } if (self.FootPoint) { self.yDelta = self.transform.position.y - self.FootPoint.position.y; self.xDelta = self.transform.position.x - self.FootPoint.position.x; } SetColor().Coroutine(); async ETVoid SetColor() { if (self.FootPoint) { Transform footEffctTran = await ResourceViewHelper.LoadPrefabAsync(Sys_PrefabId.Select); footEffctTran.name = "Select"; footEffctTran.SetParent(self.transform); footEffctTran.position = self.FootPoint.position; self.footEffect = footEffctTran.GetComponent(); self.footEffect.sortingLayerName = "FootEffct"; } SetFootEffect(self, self.unit.UnitType); } } public static void SetFootEffcetActive(this UnitView self, bool isActive, Color color) { if (!self.footEffect) return; self.footEffect.gameObject.SetActive(isActive); self.footEffect.color = color; } public static async ETTask ChangeSkin(this UnitView self, int prefabId) { HudComponent.Instance.Remove(self.unit); DestroyFootEffect(self); ResourceViewHelper.DestoryPrefabAsync(self.gameObject); self.gameObject = (await ResourceViewHelper.LoadPrefabAsync(prefabId)).gameObject; Awake(self, self.gameObject); HudComponent.Instance.Init(self.unit); NumericComponent num = self.unit.GetComponent(); ClientUnitCharacter clientUnitCharacter = ClientUnitCharacterComponent.Instance.Get(self.unit.Id); Game.EventSystem.Publish_Sync(new ET.EventType.SetHudCharacter { hp = num.GetAsInt(NumericType.Hp), maxHp = num.GetAsInt(NumericType.MaxHp), jobType = clientUnitCharacter.JobType, level = num.GetAsInt(NumericType.Level), name = clientUnitCharacter.NickName, unit = self.unit, progressTitleType = FairyGUI.ProgressTitleType.ValueAndMax }); } private static void DestroyFootEffect(UnitView self) { if (self.footEffect != null) ResourceViewHelper.DestoryPrefabAsync(self.footEffect.gameObject); } public static void SetFootEffect(this UnitView self, UnitType unitType) { Color footEffectColor = Color.white; switch (unitType) { case UnitType.None: break; case UnitType.Player: footEffectColor = Color.white; break; case UnitType.Monster: case UnitType.Enermy: case UnitType.MapMonster: footEffectColor = Color.red; break; case UnitType.OtherPlayer: footEffectColor = Color.yellow; break; case UnitType.TeamMember: footEffectColor = Color.yellow; break; default: break; } SetFootEffcetActive(self, true, footEffectColor); } } }