Unity3D and C# - Having trouble getting data from the cloud


I’m having some issues getting data from particle cloud. I am using Unity3D environment and coding it in C#. To read the data from particle cloud I use WWW class to get information from here.
But there is one problem - the stream of data from particle cloud is infinite, you can see it always updates when the link is opened in the browser and the WWW class returns the data only when it is downloaded. As the stream is endless this data acquisition can’t be done. What could be the solution for this?

For instance, I do not have problems gathering data in this form:

In this case working code right now looks like this:

using UnityEngine;
using System.Collections;
public class particle : MonoBehaviour {

	string Url = "www.ourtechart.com//wp-content/uploads/2016/04/jsonAllData.txt";

	IEnumerator Start()
		WWW www = new WWW(Url); // Start a download of the given URL (string defined elsewhere)
		yield return www; // Wait for download to complete

		// http://docs.unity3d.com/ScriptReference/WWW-text.html
		if (www.error == null)  {
			Debug.Log("Service data www: " + www);
			Debug.Log("Service data www.isDone: " + www.isDone);
			Debug.Log("Service data www.progress: " + www.progress);
			Debug.Log("Service data www.text: " + www.text); 
			Debug.Log("Service data www.bytesDownloaded: " + www.bytesDownloaded );
			Debug.Log("Service data www.size: " + www.size );

			if (www.isDone && www.error == null) {
				Debug.Log("WE'VE GOT DATA!");
		else {
			Debug.Log("Error: " + www.error);

As you can see with this example I can acquire data, what’s left - parse the data, which is not the issue.
The script should have the name “particle.cs” and attached to an empty gameObject in Unity3D.

If the String Url will be changed to the particle cloud link with access token we would not get any data as download never ends because of this: “yield return www; // Wait for download to complete”

Anyone has some ideas how to solve this?

Have a look at this?

Alternatively, try Googling for “C# eventsource”, which should give you plenty options.

Thanks, I’ll take a look ad let you know the results.

I assume that you want to do something whenever your device posts an event? If so, you’ll need to watch the events in a thread and then send that data back to the main thread to do what ever action you want. There’s lots out there if you search for unity and threading. Main thing to note is that seperate threads can’t interact with Unity Objects (Unity is not thread safe)

By researching UnityWebRequest class I founded what I needed here.

1 Like