コード例 #1
0
        //Get one onlineGame
        private IEnumerator GetOnlineGameById(string id_game, Action <OnlineGameInfo> onSuccess)
        {
            using (UnityWebRequest req = UnityWebRequest.Get(String.Format(API_GAMES_URL + id_game)))
            {
                yield return(req.SendWebRequest());

                if (req.isNetworkError || req.isHttpError)
                {
                    DebugLog.DebugMessage(req.error, true);
                    onSuccess(null);
                }
                else
                {
                    while (!req.isDone)
                    {
                        yield return(null);
                    }
                    byte[] result         = req.downloadHandler.data;
                    string onlineGameJson = System.Text.Encoding.Default.GetString(result);
                    DebugLog.DebugMessage(onlineGameJson, true);
                    OnlineGameInfo onlineGameInfo = JsonUtility.FromJson <OnlineGameInfo>(onlineGameJson);
                    onSuccess(onlineGameInfo);
                }
            }
        }
コード例 #2
0
        //Upload new waiting game request
        private IEnumerator UploadOneOnlineGame(Action <OnlineGameInfo> onSuccess)
        {
            WWWForm form = new WWWForm();

            form.AddField(FIELD1, Network.player.ipAddress);
            form.AddField(FIELD2, "");
            form.AddField(FIELD3, "");

            using (UnityWebRequest req = UnityWebRequest.Post(API_GAMES_URL, form))
            {
                yield return(req.SendWebRequest());

                if (req.isNetworkError || req.isHttpError)
                {
                    Debug.Log(req.error);
                }
                else
                {
                    while (!req.isDone)
                    {
                        yield return(null);
                    }
                    byte[] result         = req.downloadHandler.data;
                    string onlineGameJson = System.Text.Encoding.Default.GetString(result);
                    DebugLog.DebugMessage(onlineGameJson, true);
                    OnlineGameInfo onlineGameInfo = JsonUtility.FromJson <OnlineGameInfo>(onlineGameJson);
                    onSuccess(onlineGameInfo);
                }
            }
        }
コード例 #3
0
 //Set online game to waiting other player popup
 private void ShareCreatedGame(OnlineGameInfo onlineGame)
 {
     if (GetComponent <WaitingOtherPlayer>())
     {
         GetComponent <WaitingOtherPlayer>().SetCreatedOnlineGame(onlineGame);
     }
 }
コード例 #4
0
 //Say to the player if the game is available
 private void SetGameIsAvailable(OnlineGameInfo onlineGame)
 {
     DebugLog.DebugMessage("Check if game is available ...", true);
     if (GetComponent <OnlineGameList>())
     {
         if (onlineGame == null || onlineGame.starter.Equals("") || !onlineGame.listener.Equals(""))
         {
             DebugLog.DebugMessage("Game is not available", true);
             GetComponent <OnlineGameList>().JoinGameIfIsAvailable(onlineGame, false);
         }
         else
         {
             DebugLog.DebugMessage("Game is available !", true);
             GetComponent <OnlineGameList>().JoinGameIfIsAvailable(onlineGame, true);
         }
     }
 }
コード例 #5
0
        //Inform Player if a player join his created game
        private void SetAPlayerJoinTheGame(OnlineGameInfo onlineGame)
        {
            bool aPlayerJoin = false;

            if (onlineGame.listener != "")
            {
                aPlayerJoin = true;
            }
            else
            {
                aPlayerJoin = false;
            }

            if (GetComponent <WaitingOtherPlayer>())
            {
                GetComponent <WaitingOtherPlayer>().LaunchGameIf(aPlayerJoin);
            }
        }
コード例 #6
0
        //Update new waiting game Request
        private IEnumerator UpdateOneOnlineGame(OnlineGameInfo onlineGame)
        {
            WWWForm form = new WWWForm();

            form.AddField(FIELD1, onlineGame.starter);
            form.AddField(FIELD2, onlineGame.listener);
            form.AddField(FIELD3, onlineGame.id_game);

            using (UnityWebRequest www = UnityWebRequest.Post(API_GAMES_URL + onlineGame.id_game, form))
            {
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    Debug.Log("Form update complete!");
                }
            }
        }
コード例 #7
0
 //public method to post a new waiting game
 public void LaunchUpdateOnlineGame(OnlineGameInfo onlineGame)
 {
     StartCoroutine(UpdateOneOnlineGame(onlineGame));
 }