unity导入资源的编辑器设置:
防止策划资源乱导入,资源导入需要的格式
AssetPostprocessor
预处理:OnPreprocessTexture
TextureImporter imp = (TextureImporter)assetImporter;
获得图片的原始大小
TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; if(importer == null) throw new System.Exception(string.Format("GetRawTexSize failed: importer is null, path={0}", path)); object[] args = new object[2] { 0, 0 }; MethodInfo mi = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); mi.Invoke(importer, args);
通过反射使用TextureImporter.GetWidthAndHeight
imp.textureType = TextureImporterType.Sprite; imp.spriteImportMode = SpriteImportMode.Single; imp.spritePackingTag = packingTag; imp.npotScale = TextureImporterNPOTScale.None; imp.mipmapEnabled = false; imp.isReadable = true; imp.alphaIsTransparency = true; imp.wrapMode = TextureWrapMode.Clamp; imp.textureCompression = TextureImporterCompression.Uncompressed;
设置格式
后处理:OnPostprocessTexture