Unit.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 UnitType Type => (UnitType)this.Config.Type;
  11. [BsonIgnore]
  12. public UnitConfig Config => UnitConfigCategory.Instance.Get(this.ConfigId);
  13. private Vector3 position; //坐标
  14. public Vector3 Position
  15. {
  16. get => this.position;
  17. set
  18. {
  19. this.position = value;
  20. Game.EventSystem.Publish(new EventType.ChangePosition() { Unit = this }).Coroutine();
  21. }
  22. }
  23. [BsonIgnore]
  24. public Vector3 Forward
  25. {
  26. get => this.Rotation * Vector3.forward;
  27. set => this.Rotation = Quaternion.LookRotation(value, Vector3.up);
  28. }
  29. private Quaternion rotation;
  30. public Quaternion Rotation
  31. {
  32. get => this.rotation;
  33. set
  34. {
  35. this.rotation = value;
  36. Game.EventSystem.Publish(new EventType.ChangeRotation() {Unit = this}).Coroutine();
  37. }
  38. }
  39. }
  40. }