Je cherche à faire en sorte que le joueur puisse personnaliser la texture d'un objet simple en temps réel, avant mon passage en C# tout fonctionnait en Js, editeur et standalone (via WWW).
En passant en C# en éditeur je n'ai jamais de problème quand on actualise les textures, mais en standalone ça se termine systématiquement en crash out of memory.
Je ne m'y connais pas du tout en allocation de mémoire et c'est ce qui apparemment pose problème ?
Le code est le suivant:
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class GetTextures : MonoBehaviour
{
[Header("Textures")]
private string[] myPaths;
public Texture[] myTextures;
[Header("Mats à changer")]
public List<MyInts> myInts;
void Awake()
{
myPaths = new string[]{ "texture1.jpg", "texture2.jpg", "texture3.jpg","texture4.jpg","texture5.jpg","texture6.jpg"};
myTextures = new Texture[myPaths.Length];
StartCoroutine(SyncMe());
}
IEnumerator SyncMe()
{
for (int i = 0;i < myPaths.Length;i++)
{
UnityWebRequest www = UnityWebRequestTexture.GetTexture("file://C:" + "/DossierTest/" + myPaths[i]);
yield return www.SendWebRequest();
myTextures[i] = DownloadHandlerTexture.GetContent(www);
}
foreach (MyInts myDatas in myInts)
{
GetComponent<Renderer>().materials[myDatas.myMatToChange].mainTexture = myTextures[myDatas.TextureID];
}
}
void Update()
{
if (Input.GetKeyDown("space"))
{
StartCoroutine(SyncMe());
}
}
[System.Serializable]
public class MyInts
{
[Header("Material à modifier")]
public int myMatToChange;
[Header("Texture à assigner")]
public int TextureID;
}
}
Au lancement du projet ça fonctionne, je ne comprends pas pourquoi ça ne fonctionne plus ensuite ?