private void initBehaviors() { behaviorsByPlayer = new Dictionary <byte, List <TrueSyncManagedBehaviour> >(); var playersEnum = lockstep.Players.GetEnumerator(); while (playersEnum.MoveNext()) { TSPlayer p = playersEnum.Current.Value; List <TrueSyncManagedBehaviour> behaviorsInstatiated = new List <TrueSyncManagedBehaviour>(); for (int index = 0, length = playerPrefabs.Length; index < length; index++) { GameObject prefab = playerPrefabs[index]; GameObject prefabInst = Instantiate(prefab); InitializeGameObject(prefabInst, prefabInst.transform.position.ToTSVector(), prefabInst.transform.rotation.ToTSQuaternion()); TrueSyncBehaviour[] behaviours = prefabInst.GetComponentsInChildren <TrueSyncBehaviour>(); for (int index2 = 0, length2 = behaviours.Length; index2 < length2; index2++) { TrueSyncBehaviour behaviour = behaviours[index2]; behaviour.owner = p.playerInfo; behaviour.localOwner = lockstep.LocalPlayer.playerInfo; behaviour.numberOfPlayers = lockstep.Players.Count; TrueSyncManagedBehaviour tsmb = NewManagedBehavior(behaviour); tsmb.owner = behaviour.owner; tsmb.localOwner = behaviour.localOwner; behaviorsInstatiated.Add(tsmb); } } behaviorsByPlayer.Add(p.ID, behaviorsInstatiated); } }
private void OnStepUpdate(List <InputData> i_AllInputData) { // Sync time. if (m_TimeScaler != null) { m_TimeScaler.Sync(); } // PRE SYNC UPDATE // Clear input. TrueSyncInput.SetAllInputs(null); // Synced pre update on general behaviours. for (int index = 0; index < m_GeneralBehaviours.Count; ++index) { TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index]; if (tsmb == null || tsmb.disabled) { continue; } tsmb.OnPreSyncedUpdate(); } // Synced pre update on player behaviours. if (i_AllInputData != null) { for (int index = 0; index < i_AllInputData.Count; ++index) { InputData inputData = i_AllInputData[index]; if (inputData == null) { continue; } List <TrueSyncManagedBehaviour> tsmbList = null; if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList)) { for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex) { TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex]; if (tsmb == null || tsmb.disabled) { continue; } tsmb.OnPreSyncedUpdate(); } } } } // UPDATE // Set input. TrueSyncInput.SetAllInputs(i_AllInputData); TrueSyncInput.CurrentSimulationData = null; // Synced update on general behaviours. for (int index = 0; index < m_GeneralBehaviours.Count; ++index) { TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index]; if (tsmb == null || tsmb.disabled) { continue; } tsmb.OnSyncedUpdate(); } // Synced update on player behaviours. if (i_AllInputData != null) { for (int index = 0; index < i_AllInputData.Count; ++index) { InputData inputData = i_AllInputData[index]; if (inputData == null) { continue; } List <TrueSyncManagedBehaviour> tsmbList = null; if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList)) { TrueSyncInput.CurrentSimulationData = inputData; for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex) { TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex]; if (tsmb == null || tsmb.disabled) { continue; } tsmb.OnSyncedUpdate(); } } } TrueSyncInput.CurrentSimulationData = null; } // LATE UPDATE // Clear input. TrueSyncInput.SetAllInputs(null); // Synced late update on general behaviours. for (int index = 0; index < m_GeneralBehaviours.Count; ++index) { TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index]; if (tsmb == null || tsmb.disabled) { continue; } ITrueSyncBehaviour iTsb = tsmb.trueSyncBehavior; if (iTsb != null) { if (iTsb is TrueSyncBehaviour) { TrueSyncBehaviour tsb = (TrueSyncBehaviour)iTsb; tsb.OnLateSyncedUpdate(); } } } // Synced late update on player behaviours. if (i_AllInputData != null) { for (int index = 0; index < i_AllInputData.Count; ++index) { InputData inputData = i_AllInputData[index]; if (inputData == null) { continue; } List <TrueSyncManagedBehaviour> tsmbList = null; if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList)) { for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex) { TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex]; if (tsmb == null || tsmb.disabled) { continue; } ITrueSyncBehaviour iTsb = tsmb.trueSyncBehavior; if (iTsb != null) { if (iTsb is TrueSyncBehaviour) { TrueSyncBehaviour tsb = (TrueSyncBehaviour)iTsb; tsb.OnLateSyncedUpdate(); } } } } } } // Process queued behaviours. ProcessQueuedBehaviours(); }