Im using Unity 2021.3.5f and RiptideNetworking to make my multiplayer game. Befora I was doing the server on my own machine to test the connection between players on different networks and it works. Now I want to use this custom server built on Unity to the PlayFab. I follow the documentation, installed the latest SDK available and made the integration with Unity, but befora building I wanted to change from the normal build to a dedicated Server build to upload to PlayFab. But everytime I change the build type it says that the PlayFab.ServerModels library can't be found, it gives me the following error:
Assets\Scripts\ServerScripts\NetworkManager.cs(8,15): error CS0234: The type or namespace name 'ServerModels' does not exist in the namespace 'PlayFab' (are you missing an assembly reference?)
The error dosen't happen while the build type is on the default platform (Windowns, Linux, Mac). The script also dosen't have any errors, and removing the library reference just makes the lines that use it the error. I use it in the following script:
using RiptideNetworking; using RiptideNetworking.Utils; using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using PlayFab.MultiplayerAgent; using PlayFab.ServerModels; using PlayFab; //Ambos Enums devem existir no Servidor e no Client, serve para enumerar e nomear os pacotes que vão ser enviados //Cada pacote terá um nome e uma finalidade de envio e recibo de informação public enum ServerToClientId : ushort { returnConnection = 1, changeToBattleScene, sendBattleData, SendFinishedBattleInfo, ReturnFromMatchQueue, SendSkillBattleInfo, SendCharInfo, SendAllCharInfo, SendTeamInfo, SendPlayerInfo } public enum ClientToServerId : ushort{ checkConnection = 1, inputToServer, inputToMatchQueue, RequestCharInfo, RequestAllCharInfo, RequestTeamInfo, UpdateTeam, inputToPVEQueue } public class NetworkManager : MonoBehaviour { //Parte do código referente ao Singleton,sem o Awake private static NetworkManager _singleton; public static NetworkManager Singleton{ get => _singleton; private set{ if(_singleton == null){ _singleton = value; } else if(_singleton != value){ //Debug.Log($"{nameof(NetworkManager)} instance already exists, destroying duplicate!"); Destroy(value); } } } //Variável Server do próprio Riptide public Server Server {get; private set;} //Porta e máximo de client, declaradas como ushort por boas práticas do riptide [SerializeField] private ushort port; [SerializeField] private ushort maxClientCount; //Quantidade atual de Jogadores e quantidade de Batalhas [SerializeField] private int currentClients; [SerializeField] private int currentBattles; //Void Awake do Singleton private void Awake(){ Singleton = this; } private void Start(){ //Ao iniciar deixar o target de Frame Rate em 60 para estabilidade Application.targetFrameRate = 60; StartPlayFabServer(); //Chamada do Riptide responsável por futuramente pode retornar logs RiptideLogger.Initialize(Debug.Log, Debug.Log, Debug.LogWarning, Debug.LogError, false); //Iniciar um novo servidor com a porta e máximo de clients Server = new Server(); Server.Start(port, maxClientCount); //O += faz se possível uma função chamar a outra, sempre que PlayerLeft for chamado o Disconnected tbm será Server.ClientDisconnected += PlayerLeft; } #region PlayFab private void StartPlayFabServer() { PlayFabMultiplayerAgentAPI.Start(); PlayFabMultiplayerAgentAPI.IsDebugging = true; PlayFabMultiplayerAgentAPI.OnMaintenanceCallback += OnMaintenance; PlayFabMultiplayerAgentAPI.OnShutDownCallback += OnShutdown; PlayFabMultiplayerAgentAPI.OnServerActiveCallback += OnServerActive; PlayFabMultiplayerAgentAPI.OnAgentErrorCallback += OnAgentError; StartCoroutine(ReadyForPlayers()); StartCoroutine(ShutdownServerInXTime()); } private IEnumerator ReadyForPlayers() { yield return new WaitForSeconds(.5f); PlayFabMultiplayerAgentAPI.ReadyForPlayers(); } private void OnServerActive() { Debug.Log("Server Started From Agent Activation"); } private void OnShutdown() { StartShutdownProcess(); Debug.Log("Server shutdown "); } private void OnMaintenance(DateTime? NextMaintenance) { Debug.Log("Server On Maintenance. Next Maintenance - " + NextMaintenance.Value.ToLongDateString()); } private void OnAgentError(string error) { Debug.Log("Server error " + error); } IEnumerator ShutdownServerInXTime() { yield return new WaitForSeconds(300f); StartShutdownProcess(); } private void StartShutdownProcess() { Debug.Log("Server is shutting down"); StartCoroutine(ShutDownServer()); } IEnumerator ShutDownServer() { yield return new WaitForSeconds(5f); Application.Quit(); } #endregion private void FixedUpdate(){ //Tick de escuta do Servidor Server.Tick(); //Número de Jogadores é igual ao count da lista de Player no Script Player currentClients = Player.list.Count; //Número de Batalhar é igual ao count da lista de Batalhas no Script Battles Singleton currentBattles = Battles.Singleton.battleCount; } //Ao fechar o jogo o servidor irá fechar no último frame, também uma boa prática private void OnApplicationQuit(){ Server.Stop(); } //Função do Próprio Riptide que é chamado ao Riptide identificar que um Client Sair //Assim que ele sair remove da Lista de Players private void PlayerLeft(object sender, ClientDisconnectedEventArgs e) { Player.list.Remove(e.Id); } }