LSUnitViewComponentSystem.cs 2.1 KB

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