コード例 #1
0
 void OnMessage(int from, JToken data)
 {
     Debug.Log("message: " + data);
     if (from == primaryDeviceID)
     {
         mainPlayer.ButtonInput(data["action"].ToString());
         return;
     }
     //When I get a message, I check if it's from any of the devices stored in my device Id dictionary
     if (players.ContainsKey(from) && data["action"] != null)
     {
         Debug.Log($"Sending command to device [{from}], which the value in the dictionary is [{players[from]}], full dict is [{players.ToString()}]");
         //I forward the command to the relevant player script, assigned by device ID
         //CHAOTIC NULL CHECK
         if (players[from] == null)
         {
             ACInstrumentPlayer [] insPlayers = GameObject.FindObjectsOfType <ACInstrumentPlayer>();
             foreach (ACInstrumentPlayer aci in insPlayers)
             {
                 if (aci.deviceTracker == from)
                 {
                     players[from] = aci;
                     break;
                 }
             }
         }
         players[from].ButtonInput(data["action"].ToString());
     }
 }