- Home /
Textures max size
Following this articles: how to change Texture Max Size with scripting and Editor class "Texture Importer" + Apply import settings question, i realized that to change textures max size you need to save texture as an asset...
In my case, I have a BIN files that I send through the network and receive it to the (Application.persistentDataPath + "/Binaries/") path, then I retrieve the data in BINs to textures and save it as a PNG files at (Application.dataPath + "/textures/Weather/"). Now i have files, so i can change textures max size.
List<Texture2D> SetupTextures(List<string> textureNames)
{
string fileName;
List<Texture2D> textures = new List<Texture2D>();
string[] subStrings = Regex.Split(texturesData, "Assets");
string assetDatabasePath = "Assets" + subStrings [1];
//print ("AAA: " + assetDatabasePath + textureNames[0]);
foreach(string name in textureNames)
{
fileName = assetDatabasePath + name;
#if UNITY_EDITOR
TextureImporter tImporter = AssetImporter.GetAtPath( fileName ) as TextureImporter;
if( tImporter != null ) {
tImporter.mipmapEnabled = true;
tImporter.isReadable = true;
tImporter.maxTextureSize = 256;
tImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
AssetDatabase.ImportAsset( fileName, ImportAssetOptions.ForceUpdate );
//print ("TextureImporter successfully settled.");
} else {
//print ("Faild to set TextureImporter!");
}
Texture2D texture =
(Texture2D) AssetDatabase.LoadAssetAtPath (fileName, typeof(Texture2D) );
if( texture != null ) {
//renderer.material.mainTexture = texture;
//renderer.material.SetTexture("_Texture2", texture);
textures.Add(texture);
//print ("Texture successfully added to list.");
} else {
//print ("Faild to add texture to list!");
}
#endif
}
return textures;
}
The problem is that AssetImporter.GetAtPath() doesn't see the newly generated PNG files at path? but if i refocus to other window and then focus on unity they starting to load and AssetImporter.GetAtPath() gets the files as it needs.
1) So is there an any approach to do it without changing focus?
2) Or can i change Textures max size without saving it to the disc?
Your answer