private void initGeneralBehaviors(IEnumerable <FrameSyncManagedBehaviour> behaviours, bool realOwnerId) { List <FPPlayer> playersList = new List <FPPlayer>(lockstep.Players.Values); List <FrameSyncManagedBehaviour> itemsToRemove = new List <FrameSyncManagedBehaviour>(); var behavioursEnum = behaviours.GetEnumerator(); while (behavioursEnum.MoveNext()) { FrameSyncManagedBehaviour tsmb = behavioursEnum.Current; if (!(tsmb.FrameSyncBehavior is FrameSyncBehaviour)) { continue; } FrameSyncBehaviour bh = (FrameSyncBehaviour)tsmb.FrameSyncBehavior; if (realOwnerId) { bh.ownerIndex = bh.owner.Id; } else { if (bh.ownerIndex >= 0 && bh.ownerIndex < playersList.Count) { bh.ownerIndex = playersList[bh.ownerIndex].ID; } } if (behaviorsByPlayer.ContainsKey((byte)bh.ownerIndex)) { bh.owner = lockstep.Players[(byte)bh.ownerIndex].playerInfo; behaviorsByPlayer[(byte)bh.ownerIndex].Add(tsmb); itemsToRemove.Add(tsmb); } else { bh.ownerIndex = -1; } bh.localOwner = lockstep.LocalPlayer.playerInfo; bh.numberOfPlayers = lockstep.Players.Count; tsmb.owner = bh.owner; tsmb.localOwner = bh.localOwner; } for (int index = 0, length = itemsToRemove.Count; index < length; index++) { generalBehaviours.Remove(itemsToRemove[index]); } }
private void initBehaviors() { behaviorsByPlayer = new Dictionary <byte, List <FrameSyncManagedBehaviour> >(); List <FPVector> playerPosition = new List <FPVector>(); playerPosition.Add(new FPVector(-5.0f, 0, 0)); playerPosition.Add(new FPVector(-5.0f, 0, 5.0f)); int playerIndex = 0; var playersEnum = lockstep.Players.GetEnumerator(); while (playersEnum.MoveNext()) { FPPlayer p = playersEnum.Current.Value; List <FrameSyncManagedBehaviour> behaviorsInstatiated = new List <FrameSyncManagedBehaviour>(); for (int index = 0, length = playerPrefabs.Length; index < length; index++) { GameObject prefab = playerPrefabs[index]; GameObject prefabInst = Instantiate(prefab); prefabInst.transform.position = playerPosition[playerIndex].ToVector(); InitializeGameObject(prefabInst, prefabInst.transform.position.ToFPVector(), prefabInst.transform.rotation.ToFPQuaternion()); FrameSyncBehaviour[] behaviours = prefabInst.GetComponentsInChildren <FrameSyncBehaviour>(); for (int index2 = 0, length2 = behaviours.Length; index2 < length2; index2++) { FrameSyncBehaviour behaviour = behaviours[index2]; behaviour.owner = p.playerInfo; behaviour.localOwner = lockstep.LocalPlayer.playerInfo; behaviour.numberOfPlayers = lockstep.Players.Count; FrameSyncManagedBehaviour tsmb = NewManagedBehavior(behaviour); tsmb.owner = behaviour.owner; tsmb.localOwner = behaviour.localOwner; behaviorsInstatiated.Add(tsmb); } } behaviorsByPlayer.Add(p.ID, behaviorsInstatiated); playerIndex++; } }