Unit.cs 1.1 KB

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