LSUnitViewComponentSystem.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. LSWorld lsWorld = self.GetParent<Room>().LSWorld;
  20. foreach (LSUnitView child in self.Children.Values)
  21. {
  22. LSUnit unit = lsWorld.Get(child.Id) as LSUnit;
  23. Vector3 pos = child.Transform.position;
  24. Vector3 to = unit.Position.ToVector();
  25. float t = (to - pos).magnitude / 9f;
  26. child.Transform.position = Vector3.Lerp(pos, unit.Position.ToVector(), Time.deltaTime / t);
  27. }
  28. }
  29. }
  30. public static LSUnitView GetMyLsUnitView(this LSUnitViewComponent self)
  31. {
  32. return self.GetChild<LSUnitView>(self.MyId);
  33. }
  34. }
  35. }