LSUnitViewComponentSystem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using UnityEngine;
  3. namespace ET.Client
  4. {
  5. [FriendOf(typeof(LSUnitViewComponent))]
  6. public static class LSUnitViewComponentSystem
  7. {
  8. public class AwakeSystem: AwakeSystem<LSUnitViewComponent>
  9. {
  10. protected override void Awake(LSUnitViewComponent self)
  11. {
  12. self.MyId = self.Parent.GetParent<Scene>().GetComponent<PlayerComponent>().MyId;
  13. }
  14. }
  15. public class UpdateSystem: UpdateSystem<LSUnitViewComponent>
  16. {
  17. protected override void Update(LSUnitViewComponent self)
  18. {
  19. Room room = self.GetParent<Room>();
  20. LSWorld lsWorld = room.LSWorld;
  21. foreach (long playerId in room.PlayerIds)
  22. {
  23. LSUnit unit = lsWorld.LSUnitComponent.GetChild<LSUnit>(playerId);
  24. LSUnitView child = self.GetChild<LSUnitView>(playerId);
  25. Vector3 pos = child.Transform.position;
  26. Vector3 to = unit.Position.ToVector();
  27. float distance = (to - pos).magnitude;
  28. if (distance < 0.5)
  29. {
  30. continue;
  31. }
  32. float t = distance / 9f;
  33. child.Transform.position = Vector3.Lerp(pos, unit.Position.ToVector(), Time.deltaTime / t);
  34. }
  35. }
  36. }
  37. public static LSUnitView GetMyLsUnitView(this LSUnitViewComponent self)
  38. {
  39. return self.GetChild<LSUnitView>(self.MyId);
  40. }
  41. }
  42. }