// Update is called once per frame void Update() { MultiplayerSceneProperties multiplayerProperties = MultiplayerSceneProperties.Instance; // Disable enemy spawning, until both players have connected.. if (!gameStarted) { GameManager.gameManager.gameStartCounter = 5; if (!isGameManagerInitialized) { OverrideGameManagerPlayersDiscovery(); isGameManagerInitialized = true; } // Start multiplayer enemy spawning only after both players have connected.. if (multiplayerProperties.currentPlayerList.Count == 2) { GameObject p1Obj = multiplayerProperties.players[0].second; GameObject p2Obj = multiplayerProperties.players[1].second; if (p1Obj != null && p2Obj != null) { if (p1Obj.GetComponent <NetworkPlayer>().isReady&& p2Obj.GetComponent <NetworkPlayer>().isReady) { TriggerMultiplayerStart(); } } } } // Try to process the update ques multiplayerProperties.TransformsUpdateQue.Lock = true; // Lock transform update que's async running.. THIS IS F*****G DISQUSTING AND DUMB! multiplayerProperties.ActionsQue.Lock = true; multiplayerProperties.VariablesQue.Lock = true; // If current transform update que haven't been processed yet? -> do that if (!multiplayerProperties.TransformsUpdateQue.Processed) { ApplyTransformUpdateQue(); multiplayerProperties.TransformsUpdateQue.Processed = true; } multiplayerProperties.TransformsUpdateQue.Lock = false; // Allow transform update que to be set async // Update player actions.. if (!multiplayerProperties.ActionsQue.Processed) { ApplyActionQue(); } multiplayerProperties.ActionsQue.Lock = false; // Allow actions update que to be set async // Update server variables.. if (!multiplayerProperties.VariablesQue.Processed) { Random.InitState(multiplayerProperties.VariablesQue.RandomSeed); // Set random seed, generated by the server.. multiplayerProperties.VariablesQue.Processed = true; } multiplayerProperties.VariablesQue.Lock = false; // Allow server variables update que to be set async // Spawn all non spawned players, if we need to... if (ShouldUpdateLocalPlayersList) { for (int i = 0; i < multiplayerProperties.currentPlayerList.Count; i++) { multiplayerProperties.AssignNewPlayer(i); } ShouldUpdateLocalPlayersList = false; } }
// Checks MultiplayerSceneProperties's transform update que. // Applies the transforms we acquired from the server to each player. // Detects new players, we need to spawn locally from the transform update que. // Detects disconnected users, we needs to destroy locally. private void ApplyTransformUpdateQue() { TransformUpdateQue tuq = MultiplayerSceneProperties.Instance.TransformsUpdateQue; MultiplayerSceneProperties sceneProps = MultiplayerSceneProperties.Instance; ref List <byte> prevPlayerList = ref sceneProps.previousPlayerList;