// LOGIC public void Initialize(TrueSyncConfig i_Config = null) { TrueSyncConfig config = (i_Config != null) ? i_Config : (Resources.Load <TrueSyncConfig>(s_TrueSyncConfigResourcePath)); // Load config. m_Config = config; if (config == null) { return; } m_LockedTimeStep = config.lockedTimeStep; // Init state tracker. StateTracker.Init(config.rollbackWindow); // Init time. m_TimeScaler = new TSTimeScaler(); m_TimeScaler.Init(); // Create physics world. IPhysicsManager worldManager = new Physics2DWorldManager(); worldManager.Gravity = new TSVector(config.gravity.x, config.gravity.y, 0); worldManager.SpeculativeContacts = config.speculativeContacts; worldManager.LockedTimeStep = config.lockedTimeStep; worldManager.Init(); // Create communicator. ICommunicator communicator = null; if (isOnline) { communicator = new PhotonTrueSyncCommunicator(PhotonNetwork.networkingPeer); } else { Debug.Log("You are not connected to Photon. TrueSync will start in offline mode."); } // Create lockstep. m_Lockstep = AbstractLockstep.NewInstance(m_LockedTimeStep, communicator, worldManager, m_Config.syncWindow, m_Config.panicWindow, m_Config.rollbackWindow, OnGameStarted, OnGamePaused, OnGameUnPaused, OnGameEnded, OnPlayerDisconnection, OnStepUpdate, GetLocalData); Debug.Log("Lockstep initialized (Sync: " + m_Config.syncWindow + ", Rollback: " + m_Config.rollbackWindow + ")"); // Stats if (m_Config.showStats) { TrueSyncStats statsComponent = gameObject.AddComponent <TrueSyncStats>(); statsComponent.Lockstep = m_Lockstep; } // Add player on lockestep. if (isOnline) { List <PhotonPlayer> photonPlayers = new List <PhotonPlayer>(PhotonNetwork.playerList); photonPlayers.Sort(UnityUtils.playerComparer); for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Count; ++photonPlayerIndex) { PhotonPlayer photonPlayer = photonPlayers[photonPlayerIndex]; m_Lockstep.AddPlayer((byte)photonPlayer.ID, photonPlayer.NickName, photonPlayer.IsLocal); } } else { m_Lockstep.AddPlayer(0, "Local_Player", true); } // Fill behaviours per player dictionary. foreach (TSPlayer player in m_Lockstep.Players.Values) { List <TrueSyncManagedBehaviour> behaviours = new List <TrueSyncManagedBehaviour>(); m_BehavioursPerPlayer.Add(player.ID, behaviours); } // Initialize Physics Manager. PhysicsManager.Initialize(worldManager); PhysicsManager.OnRemoveBody(OnRemovedRigidbody); }