Connecting Photon to Unity3D


I am using a Photon from Particle.Io and I would like to be able to make it communicate with my Unity scene. I have started by using a JSON Parser (the Script is called SimpleJSON) and a Unity Photon library in C# (the Script is called PlayerController).

In the library there is a function called “GetVariableRaw”

public int GetVariableRaw(string varName)
HttpWebRequest request = GetHttpWebRequest(webMethod.GET, String.Format(addrCoreAPIGetVariable, this.CoreID, varName, AccessToken), string.Empty);
object jsonObj = GetHttpWebResponseAsJSONData(request, typeof(ResponseVar));
var jsonResponse = JSON.Parse(jsonObj.ToString());
return jsonResponse[“result”].AsInt;

It is used by my code like this:
light_lux = core.GetVariableRaw(“analogvalue”);
to read the variable “analogvalue” on the Particle cloud, which is the output of a photoresistor connected to my Photon.

Since this works I am now looking for a way to POST a variable on the Photon. I believe the function might be already there in the piece of code I am using but I am not sure… What should the command look like? I am using the simple tutorial where the Photon is hooked up to a LED and to Photoresistor. I would like to be able to switch on/off the LED from my Unity3D scene.

Does anyone managed to successfuly make a Particle Photon and Unity communicate together?

Thanks a lot.

What do you mean by that?
Do you want to POST a variable too the Photon? For this you’d need to have a Particle.function() set up, that can receive your variable value as String.
Or you you want to push a variable from the Photon to your Unity project? This could be done via Particle.publish() and subscribing to the SSE, or via TCPClient to talk to a C# TCP server in your project, or via HTTPClient to actually perform a HTTP POST, or plenty of other ways :wink: