RoomSystem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. LSWorld lsWorld = self.GetComponent<LSWorld>();
  12. lsWorld.AddComponent<LSUnitComponent>();
  13. for (int i = 0; i < room2CStart.UnitInfo.Count; ++i)
  14. {
  15. LockStepUnitInfo unitInfo = room2CStart.UnitInfo[i];
  16. LSUnitFactory.Init(lsWorld, unitInfo);
  17. self.PlayerIds.Add(unitInfo.PlayerId);
  18. }
  19. }
  20. public static void Update(this Room self, OneFrameMessages oneFrameMessages, int frame)
  21. {
  22. LSWorld lsWorld = self.GetComponent<LSWorld>();
  23. // 保存当前帧场景数据
  24. self.FrameBuffer.SaveLSWorld(frame, lsWorld);
  25. // 设置输入到每个LSUnit身上
  26. LSUnitComponent unitComponent = lsWorld.GetComponent<LSUnitComponent>();
  27. foreach (var kv in oneFrameMessages.Inputs)
  28. {
  29. LSUnit lsUnit = unitComponent.GetChild<LSUnit>(kv.Key);
  30. LSInputComponent lsInputComponent = lsUnit.GetComponent<LSInputComponent>();
  31. lsInputComponent.LSInput = kv.Value;
  32. }
  33. lsWorld.Update();
  34. }
  35. }
  36. }