【发布时间】:2014-05-16 20:03:33
【问题描述】:
阅读这篇文章:how to change Texture Max Size with scripting 和Editor class "Texture Importer" + Apply import settings question,我意识到要更改纹理最大尺寸,您需要将纹理保存为资产...
就我而言,我有一个 BIN 文件,我通过网络发送并将其接收到 (Application.persistentDataPath + "/Binaries/") 路径,然后我将 BIN 中的数据检索到纹理并将其保存为PNG 文件位于 (Application.dataPath + "/textures/Weather/")。现在我有了文件,所以我可以更改纹理的最大尺寸。
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;
}
问题是 AssetImporter.GetAtPath() 没有在 path 看到新生成的 PNG 文件?但如果我重新关注其他窗口,然后关注统一,他们开始加载,AssetImporter.GetAtPath() 会根据需要获取文件。
1) 那么有什么方法可以在不改变焦点的情况下做到这一点吗?
2) 或者我可以在不保存到光盘的情况下更改纹理最大尺寸吗?
【问题讨论】:
-
您是否通过代码将BIN文件转换为PNG-s?
-
是的。但是 Unity 没有看到新生成的 PNG 文件,而我没有重新聚焦到其他窗口并返回 Unity 窗口或第二次运行程序。
-
非常感谢,这正是我要找的!
标签: unity3d