/// <summary> /// deterine how the message should be handles from the middleware /// </summary> /// <param name="response"></param> /// <param name="messagetype"></param> /// <param name="command"></param> private void manageResponse(string response, string messagetype, string command) { Debug.Log(response); if (response == "Smart toy server active") { MagicRoomSmartToyManager_active = true; } else { if (response == "Smart Object not reachable on the network") { } else { if (messagetype == "getAllDevicesAndConfiguration") { response = "{\"configurations\" : " + response + "}"; SmartToyConfigurationMessage conf = JsonUtility.FromJson <SmartToyConfigurationMessage>(response); for (int i = 0; i < conf.configurations.Length; i++) { GameObject sm = GameObject.Instantiate(SmartToyPrefab); sm.GetComponent <SmartToy>().decodeConfiguration(conf.configurations[i]); sm.transform.SetParent(transform.GetChild(1)); Logger.addToLogNewLine("ServerToy", "Found configuration for smart object " + conf.configurations[i].name); } } else { if (command == "GetState") { SmartToyUpdateStatus conf = JsonUtility.FromJson <SmartToyUpdateStatus>(response); for (int i = 0; i < transform.GetChild(1).childCount; i++) { if (transform.GetChild(1).GetChild(i).name == conf.Devicestatusstate.id) { transform.GetChild(1).GetChild(i).GetComponent <SmartToy>().updateState(conf); } } } } } } }
internal void updateState(SmartToyUpdateStatus conf) { battery = conf.Devicestatusstate.battery; stream_frequency = conf.Devicestatusstate.streamFreq; if (touchsensor != null && conf.Touchstate.isEnabled) { touchsensor.updateState(conf.Touchstate); } if (button != null && conf.Buttonstate.isEnabled) { button.updateState(conf.Buttonstate); } if (rfidsensor != null && conf.RFIDstate.isEnabled) { rfidsensor.updateState(conf.RFIDstate); } if (objectposition != null && conf.Positionstate.isEnabled) { objectposition.updateState(conf.Positionstate); } if (lightcontroller != null && conf.LightControllerstate.isEnabled) { lightcontroller.updateState(conf.LightControllerstate); } if (soundemitter != null && conf.SoundEmitterstate.isEnabled) { soundemitter.updateState(conf.SoundEmitterstate); } if (motorcontroller != null && conf.Motorcontrollerstate.isEnabled) { motorcontroller.updateState(conf.Motorcontrollerstate); } if (videoemitter != null && conf.VideoEmitterstate.isEnabled) { videoemitter.updateState(conf.VideoEmitterstate); } if (effectcontroller != null && conf.Effectstate.isEnabled) { effectcontroller.updateState(conf.Effectstate); } }