Unit.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. [BsonElement]
  15. private float3 position; //坐标
  16. [BsonIgnore]
  17. public float3 Position
  18. {
  19. get => this.position;
  20. set
  21. {
  22. float3 oldPos = this.position;
  23. this.position = value;
  24. EventSystem.Instance.Publish(this.DomainScene(), new EventType.ChangePosition() { Unit = this, OldPos = oldPos });
  25. }
  26. }
  27. [BsonIgnore]
  28. public float3 Forward
  29. {
  30. get => math.mul(this.Rotation, math.forward());
  31. set => this.Rotation = quaternion.LookRotation(value, math.up());
  32. }
  33. [BsonElement]
  34. private quaternion rotation;
  35. [BsonIgnore]
  36. public quaternion Rotation
  37. {
  38. get => this.rotation;
  39. set
  40. {
  41. this.rotation = value;
  42. EventSystem.Instance.Publish(this.DomainScene(), new EventType.ChangeRotation() { Unit = this });
  43. }
  44. }
  45. protected override string ViewName
  46. {
  47. get
  48. {
  49. return $"{this.GetType().Name} ({this.Id})";
  50. }
  51. }
  52. }
  53. }