Unit.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. [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. this.position = value;
  18. Game.EventSystem.Publish(new EventType.ChangePosition() { Unit = this }).Coroutine();
  19. }
  20. }
  21. [BsonIgnore]
  22. public Vector3 Forward
  23. {
  24. get => this.Rotation * Vector3.forward;
  25. set => this.Rotation = Quaternion.LookRotation(value, Vector3.up);
  26. }
  27. private Quaternion rotation;
  28. public Quaternion Rotation
  29. {
  30. get => this.rotation;
  31. set
  32. {
  33. this.rotation = value;
  34. Game.EventSystem.Publish(new EventType.ChangeRotation() {Unit = this}).Coroutine();
  35. }
  36. }
  37. }
  38. }