I want to update my scene every 5 minutes. I am updating colors and textures. For colors is working perfect but for textures no.
If I call UpdateTexture
without StartCoroutine
nothing happens. Is i delete the StopCoroutine
statement the computer is going crazy : memory increases until it reaches 3.7 GB and unity will crash due to 32 bit limitations. How can i update my texture without the “crazy” part ?
The code i use is pasted below. Thanks in advance for your ideas.
using UnityEngine;
using System.Collections;
using System.ServiceModel;
using UnityStoreLibrary;
public class UpdateScene : MonoBehaviour {
void Start(){
StartCoroutine(UpdateMyScene());
}
IEnumerator UpdateTexture(ItemFieldValue ifv, GameObject o) {
if (!o.renderer.material.mainTexture.name.Equals(ifv.value)){
string url = "";
if (!System.IO.File.Exists(Strings.defaultUserDirectory + ifv.value))
url = Strings.texturesHost + ifv.value;
else
url = "file://" + Strings.defaultUserDirectory + ifv.value;
WWW www = new WWW (url);
yield return www;
if (!System.IO.File.Exists(Strings.defaultUserDirectory + ifv.value))
SaveTextureToFile(www.texture, ifv.value);
o.renderer.material.mainTexture = www.texture;
}
StopCoroutine("UpdateTexture"); //should i use this here ?
//yield return null;
}
private IEnumerator UpdateMyScene(){
while(true){
UnityStoreClient client = new UnityStoreClient(new BasicHttpBinding(), new EndpointAddress(Strings.webserviceUrl));
Item[] items = client.GetUnity3dItems(null);
for(int i=0;i<items.Length;i++){
GameObject curent = GameObject.Find(items*.name);*
-
if (curent != null){*
ItemFieldValue values = items*.item_field_values;
_ for(int j=0;j<values.Length;j++){_
GameObject o = GameObject.Find(curent.name + “/” + values[j].field_details.name);
_ if (o != null){*_
* if (values[j].field_details.type_id.Equals(Strings.colorType)){
_ UpdateColor (values[j], o);_
_ }_
if (values[j].field_details.type_id.Equals(Strings.textureType)){
_ StartCoroutine(UpdateTexture(values[j], o));_
_ }_
_ }_
_ }_
_ }_
_ }_
_ yield return new WaitForSeconds(Strings.updateInterval);_
_ }_
_ }_
_}*_