Skip to content

Instantly share code, notes, and snippets.

@s2kw
Created March 3, 2014 04:32
Show Gist options
  • Save s2kw/9318408 to your computer and use it in GitHub Desktop.
Save s2kw/9318408 to your computer and use it in GitHub Desktop.
画像のImport時の設定を自動化する例。
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class ImportSettingFormatter{
[MenuItem("Tools/TextureFormat")]
public static void Format()
{
Object[] images = Resources.LoadAll("image",typeof(Texture2D));
foreach(var obj in images)
{
string path = AssetDatabase.GetAssetPath(obj);
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
textureImporter.textureType = TextureImporterType.GUI;
textureImporter.maxTextureSize = 256;//ここは適当に適切なサイズを返す関数で対応すべし。
AssetDatabase.ImportAsset(path);
}
}
}
@s2kw
Copy link
Author

s2kw commented Mar 3, 2014

最初の行の…

Resources.LoadAll("image",typeof(Texture2D));

は、Resources/image/ 以下にある全てのTexture2Dとして読み取る事の出来るアセットを対象にしてるので、"image" -> "image/icon/bullet"にするなり適せん変更を。

TextureTypeはGUI以外にすると正方形に変身してしまいます。
maxTextureSizeは、pathからどのディレクトリに格納されているかを正規表現などで条件分けしてint(ただし、2のべき乗)を返す関数などで対応しておりましたよ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment