Esempio n. 1
0
    // create and send a SpawnRequestForm
    IEnumerator SendSpawnRequest(int _laneNum, GameControl.Sides _side, int _selectedCreatureType)
    {
        try
        {
            Byte[] buffer = new Byte[bufferSize];

            // save variables to class sending through socket
            SpawnRequestForm spawnRequestForm = new SpawnRequestForm();
            spawnRequestForm.SetlaneNum(_laneNum);
            spawnRequestForm.SetSelectedCreatureType(_selectedCreatureType);
            spawnRequestForm.SetSide(_side);

            // create a JSON string with SpawnRequestForm instance
            string serverMessage = JsonUtility.ToJson(spawnRequestForm);
            buffer = Encoding.ASCII.GetBytes(serverMessage);
            serverControl.GetServerStream().Write(buffer, 0, buffer.Length);

            ClearBuffer(buffer);
        }
        catch (SocketException socketException)
        {
            Debug.Log("SocketException " + socketException.ToString());
        }

        yield return(null);
    }
Esempio n. 2
0
 // create and set information of SpawnRequestForm
 public void ReceiveSpawnRequest(string jsonString)
 {
     try
     {
         Debug.Log(jsonString);
         SpawnRequestForm newRequestForm = new SpawnRequestForm();
         newRequestForm = JsonUtility.FromJson <SpawnRequestForm>(jsonString);
         lock (lock_spawn)
         {
             spawnQueue.Enqueue(newRequestForm);
         }
     }
     catch (ArgumentException argumentException)
     {
         Debug.Log("ArgumentException " + argumentException.ToString());
     }
     return;
 }