Unit.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 partial class Unit: Entity, IAwake<int>
  9. {
  10. public int ConfigId { get; set; } //配置表id
  11. [BsonElement]
  12. private float3 position; //坐标
  13. [BsonIgnore]
  14. public float3 Position
  15. {
  16. get => this.position;
  17. set
  18. {
  19. float3 oldPos = this.position;
  20. this.position = value;
  21. EventSystem.Instance.Publish(this.Scene(), new ChangePosition() { Unit = this, OldPos = oldPos });
  22. }
  23. }
  24. [BsonIgnore]
  25. public float3 Forward
  26. {
  27. get => math.mul(this.Rotation, math.forward());
  28. set => this.Rotation = quaternion.LookRotation(value, math.up());
  29. }
  30. [BsonElement]
  31. private quaternion rotation;
  32. [BsonIgnore]
  33. public quaternion Rotation
  34. {
  35. get => this.rotation;
  36. set
  37. {
  38. this.rotation = value;
  39. EventSystem.Instance.Publish(this.Scene(), new ChangeRotation() { Unit = this });
  40. }
  41. }
  42. protected override string ViewName
  43. {
  44. get
  45. {
  46. return $"{this.GetType().FullName} ({this.Id})";
  47. }
  48. }
  49. }
  50. }