Unit.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Diagnostics;
  2. using MongoDB.Bson.Serialization.Attributes;
  3. using UnityEngine;
  4. namespace ET
  5. {
  6. [ChildOf(typeof(UnitComponent))]
  7. [DebuggerDisplay("DebuggerDisplay,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 Vector3 position; //坐标
  16. [BsonIgnore]
  17. public Vector3 Position
  18. {
  19. get => this.position;
  20. set
  21. {
  22. Vector3 oldPos = this.position;
  23. this.position = value;
  24. Game.EventSystem.Publish(this.DomainScene(), new EventType.ChangePosition() { Unit = this, OldPos = oldPos });
  25. }
  26. }
  27. [BsonIgnore]
  28. public Vector3 Forward
  29. {
  30. get => this.Rotation * Vector3.forward;
  31. set => this.Rotation = Quaternion.LookRotation(value, Vector3.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. Game.EventSystem.Publish(this.DomainScene(), new EventType.ChangeRotation() { Unit = this });
  43. }
  44. }
  45. private string DebuggerDisplay => this.Config.Name;
  46. #if ENABLE_CODES
  47. protected override string ViewGoName
  48. {
  49. get
  50. {
  51. return $"{this.GetType().Name} ({this.Id})";
  52. }
  53. }
  54. #endif
  55. }
  56. }