Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 18, 2014 03:17
Show Gist options
  • Select an option

  • Save baba-s/9612929 to your computer and use it in GitHub Desktop.

Select an option

Save baba-s/9612929 to your computer and use it in GitHub Desktop.
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