//Gets an unused color for the player public Color ServerGetColor(TanksNetworkPlayer player) { Color playerColor = player.color; int index = System.Array.IndexOf(m_Colors, playerColor); if (index == -1) { index = Random.Range(0, m_Colors.Length); } else { m_ColorsInUse.Remove(index); } int uniqueIndex = index; bool isUnique = false; while (!isUnique) { uniqueIndex++; if (uniqueIndex == m_Colors.Length) { uniqueIndex = 0; } if (!m_ColorsInUse.Contains(uniqueIndex)) { isUnique = true; m_ColorsInUse.Add(uniqueIndex); } } return(m_Colors[uniqueIndex]); }
/// <summary> /// Set up this tank with the correct properties /// </summary> private void Initialize(TanksNetworkPlayer player) { if (initialized) { return; } initialized = true; this.player = player; playerTankType = TankLibrary.s_Instance.GetTankDataForIndex(player.tankType); // Create visual tank GameObject tankDisplay = (GameObject)Instantiate(playerTankType.displayPrefab, transform.position, transform.rotation); tankDisplay.transform.SetParent(transform, true); // Analytics messages on server if (isServer) { AnalyticsHelper.PlayerUsedTankInGame(playerTankType.id); TankDecorationDefinition itemData = TankDecorationLibrary.s_Instance.GetDecorationForIndex(player.tankDecoration); if (itemData.id != "none") { AnalyticsHelper.PlayerUsedDecorationInGame(itemData.id); } } // Get references to the components. display = tankDisplay.GetComponent <TankDisplay>(); movement = GetComponent <TankMovement>(); shooting = GetComponent <TankShooting>(); health = GetComponent <TankHealth>(); // Initialize components movement.Init(this); shooting.Init(this); health.Init(this); display.Init(this); GameManager.AddTank(this); if (player.hasAuthority) { DisableShooting(); player.CmdSetReady(); } }
//Get the available color public Color ServerGetColor(TanksNetworkPlayer player) { int playerIndex = m_Players.IndexOf(player); if (playerIndex == -1) { m_Players.Add(player); playerIndex = m_Players.Count - 1; } Color playerColor = player.color; int index = m_Colors.IndexOf(playerColor); if (index == -1) { //Ensure that the first two tanks aren't both the same colours index = Random.Range(0, m_Colors.Count); while (index == m_LastUsedColorIndex) { index = Random.Range(0, m_Colors.Count); } m_LastUsedColorIndex = index; } else { index++; } if (index == m_Colors.Count) { index = 0; } Color newColor = m_Colors[index]; if (CanUseColor(newColor, playerIndex)) { return(newColor); } return(playerColor); }
/// ------------------------------------------------------------------------------------------------------ /// <summary> /// Set up this tank with the correct properties /// </summary> /// ------------------------------------------------------------------------------------------------------ private void Initialize(TanksNetworkPlayer player) { if (initialized) { return; } initialized = true; this.player = player; playerTankType = TankLibrary.s_Instance.GetTankDataForIndex(player.tankType); // Analytics messages on server if (isServer) { AnalyticsHelper.PlayerUsedTankInGame(playerTankType.id); } // Create visual tank player.transform.position = transform.position; player.transform.SetParent(transform, true); if (isServer) { AnalyticsHelper.PlayerUsedTankInGame(playerTankType.id); } hudPlayer = HUDPlayerManager.Get().CreateHUDPlayerPrefab(transform); movement = GetComponent <TankMovement>(); shooting = GetComponent <TankShooting>(); movement.Init(this); hudPlayer.Init(transform); shooting.SetPlayerWeapon(0); GameManager.AddTank(this); if (player.hasAuthority) { DisableShooting(); player.CmdSetReady(); } }
// Exits the game. public void ExitGame(MenuPage returnPage) { for (int i = 0; i < s_Tanks.Count; i++) { TankManager tank = s_Tanks[i]; if (tank != null) { TanksNetworkPlayer player = tank.player; if (player != null) { player.tank = null; } NetworkServer.Destroy(s_Tanks[i].gameObject); } } s_Tanks.Clear(); m_NetManager.ReturnToMenu(returnPage); }
IEnumerator SetupVideoSurface(TanksNetworkPlayer player) { Debug.Log("Tank initializing player:" + player); yield return(new WaitForFixedUpdate()); if (player.hasAuthority) { // doesn't seem necessary // DisableShooting(); } player.CmdSetReady(); if (videoSurface == null) { videoSurface = RenderObject.AddComponent <VideoSurface>(); } if (player.isLocalPlayer) { if (videoSurface != null) { videoSurface.gameObject.name = LocalTankVideoName; } } else { uint uid = AgoraPlayerController.instance.GetAgoraID(player); Debug.LogFormat("Tank player {0}: Found agora uid for player ------> {1} ", player, uid); if (uid != 0 && videoSurface != null) { videoSurface.gameObject.name = string.Format("video-{0}", uid); videoSurface.SetForUser(uid); } else { Debug.Assert(uid != 0, "Couldn't find uid for player:" + player.playerId); AgoraPlayerController.instance.Print(); Debug.Assert(videoSurface != null, "videoSurface = null"); } } }