Created
March 18, 2014 03:17
-
-
Save baba-s/9612929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.IO; | |
| using UnityEditor; | |
| /// <summary> | |
| /// アセットをインポートする時の処理を記述します | |
| /// </summary> | |
| public class TexturePreprocessor : AssetPostprocessor | |
| { | |
| /// <summary> | |
| /// テクスチャをインポートする直前に呼び出されます | |
| /// </summary> | |
| private void OnPreprocessTexture() | |
| { | |
| // すでにメタファイルが存在する場合は設定を変更しない | |
| if (IsExistMetafile()) | |
| { | |
| return; | |
| } | |
| // Texture TypeはAdvanced | |
| // ミップマップは生成しない | |
| // FormatはARGB 16 bit | |
| var importer = assetImporter as TextureImporter; | |
| importer.textureType = TextureImporterType.Advanced; | |
| importer.mipmapEnabled = false; | |
| importer.textureFormat = TextureImporterFormat.ARGB16; | |
| } | |
| /// <summary> | |
| /// メタファイルが存在するかどうかを確認する | |
| /// </summary> | |
| private bool IsExistMetafile() | |
| { | |
| var assetPath = assetImporter.assetPath; | |
| var directoryName = Path.GetDirectoryName(assetPath); | |
| var filename = Path.GetFileName(assetPath); | |
| var metafile = directoryName + "/" + filename + ".meta"; | |
| return File.Exists(metafile); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment