using ET; using Cal.DataTable; using System; using UnityEngine; namespace ET { public class UnitAwakeSystem : AwakeSystem { public override void Awake(Unit self) { self.Awake(); } } public class UnitDestroySystem : DestroySystem { public override void Destroy(Unit self) { self.Destroy(); } } public sealed class Unit : Entity { public enum State { Idle,Move,Battle,Trans} public int ConfigId; public State state{ get; set; } public bool IsLeader => Id == LeaderId; public long LeaderId; public bool IsFight { get; set; } public bool IsAlive { get; set; } private UnitType unitType; public UnitType UnitType { get => unitType; set { if (unitType == value) return; unitType = value; switch (unitType) { case UnitType.None: case UnitType.Player: case UnitType.MainStoryMonster: case UnitType.TrialCopyMonster: case UnitType.ManulEquipMonster: case UnitType.BossMonster: case UnitType.Enermy: case UnitType.TeamMember: HideUnitComponent.Remove(this); break; case UnitType.OtherPlayer: case UnitType.NPC: case UnitType.MapMonster: case UnitType.TransPoint: case UnitType.SceneUnit: HideUnitComponent.Add(this); break; default: break; } Game.EventSystem.Publish_Sync(new ET.EventType.UpdateUnitType { unit = this, }); } } public int SkinId { get { var num = GetComponent(); if (num == null) { Log.Warning($"num == null where id = {Id}"); return 0; } return num.GetAsInt(NumericType.SkinId); } } public void Awake() { LeaderId = Id; IsFight = false; IsAlive = true; } private Vector3 position; public Vector3 Position { get { return position; } set { if (position == value) return; position = value; RefreshPosition(); } } public void RefreshPosition() { Game.EventSystem.Publish_Sync(new ET.EventType.UpdateUnitPosition { unit = this, pos = position }); } private int yAngle; public int YAngle { get => yAngle; set { if (yAngle == value) return; yAngle = value; Game.EventSystem.Publish_Sync(new ET.EventType.UpdateUnitAngle { unit = this, yAngle = value }); } } public override void Dispose() { if (!this) return; Game.EventSystem.Publish_Sync(new ET.EventType.OnDisposeUnit { unit = this }); base.Dispose(); } public void Destroy() { ClientUnitCharacterComponent.Instance.Remove(this); HideUnitComponent.Remove(this); yAngle = 0; position = default; LeaderId = 0; IsAlive = false; IsFight = false; } } }