Using System. Collections. Generic;
Using System. IO;
Using UnityEngine;
Using UnityEngine. UI;
Public class GetMaterials: MonoBehaviour
{
Public GameObject [] meshRenderer;
Private void the Start ()
{
StartCoroutine (GetRawimage ());
}
IEnumerator GetRawimage ()
{
for (int i=0; i
Yield return new WaitForSeconds (0.1 f);
String strname=Application. DataPath + @ \ StreamingAssets \ Materials \ "" + meshRenderer [I] name +" PNG ";//model name and consistent picture name
If (the File. The Exists (strname))
{
Texture2D tx=new Texture2D (100, 100);
Tx. LoadImage (getImageByte (strname));
MeshRenderer mes=MeshRenderer [I] GetComponent
Mes. Material. MainTexture=tx;
StartCoroutine (ToDestoryThis ());
}
}
}
Private static byte [] getImageByte (string imagePath)
{
FileStream files=new FileStream (imagePath, FileMode. Open);
Byte [] imgByte=new byte [files. Length];
Files. Read (imgByte, 0, imgByte. Length);
Files. The Close ();
Return imgByte;
}
IEnumerator ToDestoryThis ()
{
Yield return new WaitForSeconds (0.1 f);
Resources. UnloadUnusedAssets ();//unloading free asset resources
System. The GC. Collect ();//recycling memory
}
}