Unit.cs 1.2 KB

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