Unit.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Diagnostics;
  2. using MongoDB.Bson.Serialization.Attributes;
  3. using Unity.Mathematics;
  4. namespace ET
  5. {
  6. [ChildOf(typeof(UnitComponent))]
  7. [DebuggerDisplay("ViewName,nq")]
  8. public class Unit: Entity, IAwake<int>
  9. {
  10. public int ConfigId { get; set; } //配置表id
  11. [BsonIgnore]
  12. public UnitConfig Config => UnitConfigCategory.Instance.Get(this.ConfigId);
  13. public UnitType Type => (UnitType)UnitConfigCategory.Instance.Get(this.ConfigId).Type;
  14. [BsonIgnore]
  15. public bool IsActor
  16. {
  17. get; set;
  18. }
  19. [BsonElement]
  20. private float3 position; //坐标
  21. [BsonIgnore]
  22. public float3 Position
  23. {
  24. get => this.position;
  25. set
  26. {
  27. float3 oldPos = this.position;
  28. this.position = value;
  29. EventSystem.Instance.Publish(this.DomainScene(), new EventType.ChangePosition() { Unit = this, OldPos = oldPos });
  30. }
  31. }
  32. [BsonIgnore]
  33. public float3 Forward
  34. {
  35. get => math.mul(this.Rotation, math.forward());
  36. set => this.Rotation = quaternion.LookRotation(value, math.up());
  37. }
  38. [BsonElement]
  39. private quaternion rotation;
  40. [BsonIgnore]
  41. public quaternion Rotation
  42. {
  43. get => this.rotation;
  44. set
  45. {
  46. this.rotation = value;
  47. EventSystem.Instance.Publish(this.DomainScene(), new EventType.ChangeRotation() { Unit = this });
  48. }
  49. }
  50. protected override string ViewName
  51. {
  52. get
  53. {
  54. return $"{this.GetType().Name} ({this.Id})";
  55. }
  56. }
  57. }
  58. }