Unit.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using MongoDB.Bson.Serialization.Attributes;
  3. using UnityEngine;
  4. namespace ET
  5. {
  6. [BsonIgnoreExtraElements]
  7. public sealed class Unit: Entity
  8. {
  9. public int ConfigId; //配置表id
  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. }