public void treatMessage(object s, MessageEventArgs e) { var generalResult = JsonUtility.FromJson <ResultClass>(e.Data); if (controller.gamePaused == false) { if (generalResult.id == 1) { var res = JsonUtility.FromJson <NewSessionResultClass> (e.Data); globalscripts.session = res.result; } //receiveing confirmation of accelerometer stream else if (generalResult.id == 2) //if this is connection data { Debug.Log("Received answer for creating new subscription to accelerometer stream..."); } else if (e.Data.IndexOf("\"jsonrpc\":\"2.0\"") == -1 && e.Data.IndexOf("\"mot\"") != -1) //mot information data { UnityMainThreadDispatcher.Instance().Enqueue(GetTime()); motEventClass motResult = JsonUtility.FromJson <motEventClass> (e.Data); //x axis = 4 xAxis = motResult.mot [4]; //y axis yAxis = motResult.mot [5]; //z axis = 6 zAxis = motResult.mot [6]; if (globalscripts.firstUpdate == false) { globalscripts.updateFirstShipPosition(xAxis, yAxis, zAxis); firstX = globalscripts.firstX; firstY = globalscripts.firstY; firstZ = globalscripts.firstZ; } } } }
public void treatMessage(object s, MessageEventArgs e) { var generalResult = JsonUtility.FromJson <ResultClass>(e.Data); if (controller.gamePaused == false) { if (generalResult.id == 1) { var res = JsonUtility.FromJson <NewSessionResultClass> (e.Data); globalscripts.session = res.result; } //receiveing confirmation of accelerometer stream else if (generalResult.id == 2) //if this is connection data { Debug.Log("Received answer for creating new subscription to accelerometer/facial streams..."); } else if (e.Data.IndexOf("\"jsonrpc\":\"2.0\"") == -1 && e.Data.IndexOf("\"mot\"") != -1) //mot information data { motEventClass motResult = JsonUtility.FromJson <motEventClass> (e.Data); UnityMainThreadDispatcher.Instance().Enqueue(GetTime()); //x axis = 4 xAxis = motResult.mot [4]; //y axis yAxis = motResult.mot [5]; //z axis = 6 zAxis = motResult.mot [6]; if (globalscripts.firstUpdate == false) { globalscripts.updateFirstShipPosition(xAxis, yAxis, zAxis); firstX = globalscripts.firstX; firstY = globalscripts.firstY; firstZ = globalscripts.firstZ; } } else if (e.Data.IndexOf("\"jsonrpc\":\"2.0\"") == -1 && e.Data.IndexOf("\"fac\"") != -1) //fac information data //test if frown { if (e.Data.IndexOf("\"frown\"") != -1) { UnityMainThreadDispatcher.Instance().Enqueue(GetFrownValue(e.Data)); if (frownValue > 0.5f && Time.time > nextFire) { nextFire = Time.time + fireRate; UnityMainThreadDispatcher.Instance().Enqueue(Shoot3()); } } } else if (e.Data.IndexOf("\"jsonrpc\":\"2.0\"") == -1 && e.Data.IndexOf("\"met\"") != -1) { bcolor.r = originalRed; bcolor.g = originalGreen; metEventClass metResult = JsonUtility.FromJson <metEventClass> (e.Data); if ((metResult.met [1] == 0.0f && metResult.met [2] == 0.0f) || (Mathf.Abs(metResult.met [1] - metResult.met [2]) <= 0.05)) { //Debug.Log ("You're neutral:" + metResult.met [1] + ", " + metResult.met [2]); } else if (metResult.met [1] > (metResult.met [2] * 0.9)) //if stress is bigger than relax { bcolor.r = bcolor.r + metResult.met [1] * 10; } else { bcolor.g = bcolor.g + metResult.met [2] * 10; } UnityMainThreadDispatcher.Instance().Enqueue(changeBackground()); } } }