Entity.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using UnityEngine;
  3. namespace FL.Battle
  4. {
  5. public abstract class Entity : IEntity, IDisposable
  6. {
  7. public int TableId => Attr.TableId;
  8. public long EntityId { get; private set; }
  9. public EntityAttributes Attr { get; private set; }
  10. public int[] ActiveSkillIds { get; private set; }
  11. public int[] PassiveSkillIds { get; private set; }
  12. /// <summary>
  13. /// 出生坐标
  14. /// 相对于地图根节点的坐标
  15. /// </summary>
  16. public Vector3 BirthPosition { get; set; }
  17. //public EEntityState State { get; set; }
  18. public bool IsIdle => _states == 0;
  19. public bool IsDead => IsState(EEntityState.Dead);
  20. private EEntityState _states = 0;
  21. public bool AddState(EEntityState state)
  22. {
  23. var last = _states;
  24. _states |= state;
  25. return last != _states;
  26. }
  27. public bool RemoveState(EEntityState state)
  28. {
  29. var last = _states;
  30. _states &= ~state;
  31. return last != _states;
  32. }
  33. public bool IsState(EEntityState state)
  34. {
  35. return (_states & state) != 0;
  36. }
  37. public void Init(long entityId, EntityAttributes attr, int[] activeSkillIds, int[] passiveSkillIds = null)
  38. {
  39. EntityId = entityId;
  40. Attr = attr;
  41. ActiveSkillIds = activeSkillIds;
  42. PassiveSkillIds = passiveSkillIds;
  43. _states = 0;
  44. }
  45. void IDisposable.Dispose()
  46. {
  47. //_states = 0;
  48. OnDispose();
  49. (Attr as IDisposable)?.Dispose();
  50. }
  51. public abstract EEntityType EntityType { get; }
  52. protected virtual void OnDispose()
  53. {
  54. }
  55. }
  56. }