RoomSystem.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. namespace ET
  3. {
  4. [FriendOf(typeof(Room))]
  5. public static class RoomSystem
  6. {
  7. public static void Init(this Room self, Room2C_Start room2CStart)
  8. {
  9. self.StartTime = room2CStart.StartTime;
  10. self.FixedTimeCounter = new FixedTimeCounter(self.StartTime, 0, LSConstValue.UpdateInterval);
  11. self.LSWorld.AddComponent<LSUnitComponent>();
  12. for (int i = 0; i < room2CStart.UnitInfo.Count; ++i)
  13. {
  14. LockStepUnitInfo unitInfo = room2CStart.UnitInfo[i];
  15. LSUnitFactory.Init(self.LSWorld, unitInfo);
  16. }
  17. }
  18. public static void Update(this Room self, OneFrameMessages oneFrameMessages, int frame)
  19. {
  20. // 保存当前帧场景数据
  21. self.FrameBuffer.SaveLSWorld(frame, self.LSWorld);
  22. // 设置输入到每个LSUnit身上
  23. LSWorld lsWorld = self.LSWorld;
  24. LSUnitComponent unitComponent = lsWorld.GetComponent<LSUnitComponent>();
  25. foreach (var kv in oneFrameMessages.Inputs)
  26. {
  27. LSUnit lsUnit = unitComponent.GetChild<LSUnit>(kv.Key);
  28. LSInputComponent lsInputComponent = lsUnit.GetComponent<LSInputComponent>();
  29. lsInputComponent.LSInput = kv.Value;
  30. }
  31. lsWorld.Updater.Update();
  32. }
  33. }
  34. }