Unit.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using MongoDB.Bson.Serialization.Attributes;
  2. using UnityEngine;
  3. namespace ET
  4. {
  5. [ChildOf(typeof(UnitComponent))]
  6. public class Unit: Entity, IAwake<int>
  7. {
  8. public int ConfigId { get; set; } //配置表id
  9. [BsonIgnore]
  10. public UnitConfig Config => UnitConfigCategory.Instance.Get(this.ConfigId);
  11. public UnitType Type => (UnitType)UnitConfigCategory.Instance.Get(this.ConfigId).Type;
  12. [BsonElement]
  13. private Vector3 position; //坐标
  14. [BsonIgnore]
  15. public Vector3 Position
  16. {
  17. get => this.position;
  18. set
  19. {
  20. Vector3 oldPos = this.position;
  21. this.position = value;
  22. Game.EventSystem.Publish(this, new EventType.ChangePosition() { OldPos = oldPos });
  23. }
  24. }
  25. [BsonIgnore]
  26. public Vector3 Forward
  27. {
  28. get => this.Rotation * Vector3.forward;
  29. set => this.Rotation = Quaternion.LookRotation(value, Vector3.up);
  30. }
  31. [BsonElement]
  32. private Quaternion rotation;
  33. [BsonIgnore]
  34. public Quaternion Rotation
  35. {
  36. get => this.rotation;
  37. set
  38. {
  39. this.rotation = value;
  40. Game.EventSystem.Publish(this, new EventType.ChangeRotation());
  41. }
  42. }
  43. }
  44. }