Unit.cs 1.3 KB

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