Unit.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using MongoDB.Bson.Serialization.Attributes;
  3. using UnityEngine;
  4. namespace ET
  5. {
  6. public sealed class Unit: Entity
  7. {
  8. public int ConfigId; //配置表id
  9. public UnitType Type;
  10. [BsonIgnore]
  11. public UnitConfig Config => UnitConfigCategory.Instance.Get(this.ConfigId);
  12. private Vector3 position; //坐标
  13. public Vector3 Position
  14. {
  15. get => this.position;
  16. set
  17. {
  18. this.position = value;
  19. Game.EventSystem.Publish(new EventType.ChangePosition() { Unit = this }).Coroutine();
  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}).Coroutine();
  36. }
  37. }
  38. }
  39. }