I am working on one paint tool. There are some textures which get painted at runtime and some don’t. But when my mouse pointer goes on texture which are not readable it throws exception. How do i check Read/Write Enabled property of Texture Importer runtime from my javascript.[10014-texture+importer+settingspng.png|10014]
2 Answers
2I also needed to check if read/write was enabled. I came up with the solution myself:
NOTE: Solution is in C#
try
{
texture.GetPixel(0, 0);
}
catch(UnityException e)
{
if(e.Message.StartsWith("Texture '" + texture.name + "' is not readable"))
{
Debug.LogError("Please enable read/write on texture [" + texture.name + "]");
}
}
Hopefully this will help anyone else who needs a solution to this problem.
TextureImporter importer = AssetImporter.GetAtPath (path)as TextureImporter;
importer.isReadable = true;
“path” is the texture path you wanna change.
The question says at runtime. And the AssetImporter is a UnityEditor class.
– Celtc