using System; using UnityEngine; namespace ET.Client { [FriendOf(typeof(LSUnitViewComponent))] public static class LSUnitViewComponentSystem { public class AwakeSystem: AwakeSystem { protected override void Awake(LSUnitViewComponent self) { self.MyId = self.Parent.GetParent().GetComponent().MyId; } } public class RollbackSystem: RollbackSystem { protected override void Rollback(LSUnitViewComponent self) { LSWorld lsWorld = self.GetParent().LSWorld; foreach (LSUnitView child in self.Children.Values) { LSUnit unit = lsWorld.Get(child.Id) as LSUnit; Vector3 pos = child.Transform.position; Vector3 to = unit.Position.ToVector(); float t = (to - pos).magnitude / 9f; child.Transform.position = pos; } } } public class UpdateSystem: UpdateSystem { protected override void Update(LSUnitViewComponent self) { LSWorld lsWorld = self.GetParent().LSWorld; foreach (LSUnitView child in self.Children.Values) { LSUnit unit = lsWorld.Get(child.Id) as LSUnit; Vector3 pos = child.Transform.position; Vector3 to = unit.Position.ToVector(); float t = (to - pos).magnitude / 9f; child.Transform.position = Vector3.Lerp(pos, unit.Position.ToVector(), Time.deltaTime / t); } } } public static LSUnitView GetMyLsUnitView(this LSUnitViewComponent self) { return self.GetChild(self.MyId); } } }