LSUnitViewSystem.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using UnityEngine;
  3. namespace ET.Client
  4. {
  5. public static class LSUnitViewSystem
  6. {
  7. public class AwakeSystem: AwakeSystem<LSUnitView, GameObject>
  8. {
  9. protected override void Awake(LSUnitView self, GameObject go)
  10. {
  11. self.GameObject = go;
  12. self.Transform = go.transform;
  13. }
  14. }
  15. public class UpdateSystem: UpdateSystem<LSUnitView>
  16. {
  17. protected override void Update(LSUnitView self)
  18. {
  19. self.Update();
  20. }
  21. }
  22. private static void Update(this LSUnitView self)
  23. {
  24. LSUnit unit = self.GetUnit();
  25. Vector3 pos = self.Transform.position;
  26. Vector3 to = unit.Position.ToVector();
  27. float distance = (to - pos).magnitude;
  28. //if (distance < 0.5)
  29. //{
  30. // return;
  31. //}
  32. float t = distance / 9f;
  33. self.Transform.position = Vector3.Lerp(pos, unit.Position.ToVector(), Time.deltaTime / t);
  34. }
  35. public static LSUnit GetUnit(this LSUnitView self)
  36. {
  37. LSUnit unit = self.Unit;
  38. if (unit != null)
  39. {
  40. return unit;
  41. }
  42. self.Unit = (self.Domain as Room).LSWorld.GetComponent<LSUnitComponent>().GetChild<LSUnit>(self.Id);
  43. return self.Unit;
  44. }
  45. }
  46. }