LSUnitViewComponentSystem.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 RollbackSystem: RollbackSystem<LSUnitViewComponent>
  16. {
  17. protected override void Rollback(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 = pos;
  27. }
  28. }
  29. }
  30. public class UpdateSystem: UpdateSystem<LSUnitViewComponent>
  31. {
  32. protected override void Update(LSUnitViewComponent self)
  33. {
  34. LSWorld lsWorld = self.GetParent<Room>().LSWorld;
  35. foreach (LSUnitView child in self.Children.Values)
  36. {
  37. LSUnit unit = lsWorld.Get(child.Id) as LSUnit;
  38. Vector3 pos = child.Transform.position;
  39. Vector3 to = unit.Position.ToVector();
  40. float t = (to - pos).magnitude / 9f;
  41. child.Transform.position = Vector3.Lerp(pos, unit.Position.ToVector(), Time.deltaTime / t);
  42. }
  43. }
  44. }
  45. public static LSUnitView GetMyLsUnitView(this LSUnitViewComponent self)
  46. {
  47. return self.GetChild<LSUnitView>(self.MyId);
  48. }
  49. }
  50. }