Created
March 8, 2017 12:02
-
-
Save st0326s/00e380df487bde4cfae7c07bd8d6279b to your computer and use it in GitHub Desktop.
Unity上でのテクスチャサイズ一覧取得 ref: http://qiita.com/satotin/items/a0e43dddfd0df1fbff19
This file contains 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 UnityEngine; | |
using UnityEditor; | |
using System.Reflection; | |
using System; | |
public static class CalcTextureSize | |
{ | |
private static Type mType; | |
private static MethodInfo mGetTextureFormat; | |
private static MethodInfo mCountMipmaps; | |
private static MethodInfo mGetStorageMemorySize; | |
private static MethodInfo mHasAlphaTextureFormat; | |
private static MethodInfo mIsCompressedTextureFormat; | |
private static MethodInfo mIsNonPowerOfTwo; | |
private static MethodInfo mGetGLWidth; | |
private static MethodInfo mGetGLHeight; | |
static void TextureInitial() | |
{ | |
string typeName = "UnityEditor.TextureUtil"; | |
mType = System.Reflection.Assembly.Load("UnityEditor.dll").GetType(typeName); | |
if (mType == null) | |
{ | |
return; | |
} | |
mCountMipmaps = mType.GetMethod("CountMipmaps", BindingFlags.Static | BindingFlags.Public); | |
mGetStorageMemorySize = mType.GetMethod("GetStorageMemorySize", BindingFlags.Static | BindingFlags.Public); | |
mGetTextureFormat = mType.GetMethod("GetTextureFormat", BindingFlags.Static | BindingFlags.Public); | |
mGetGLHeight = mType.GetMethod("GetGLHeight", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(Texture) }, null); | |
mGetGLWidth = mType.GetMethod("GetGLWidth", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(Texture) }, null); | |
mHasAlphaTextureFormat = mType.GetMethod("HasAlphaTextureFormat", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(TextureFormat) }, null); | |
mIsCompressedTextureFormat = mType.GetMethod("IsCompressedTextureFormat", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(TextureFormat) }, null); | |
mIsNonPowerOfTwo = mType.GetMethod("IsNonPowerOfTwo", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(Texture2D) }, null); | |
} | |
[MenuItem("Texture/Check")] | |
public static void TextureCheck() | |
{ | |
TextureInitial(); | |
string filter = "t:Texture2D"; | |
string[] guids = AssetDatabase.FindAssets(filter); | |
System.Text.Encoding utf8Enc = System.Text.Encoding.GetEncoding("utf-8"); | |
System.IO.StreamWriter writer = new System.IO.StreamWriter("FileSize.csv", false, utf8Enc); | |
writer.WriteLine("パス,サイズ,フォーマット"); | |
for (int i = 0; i < guids.Length; i++) | |
{ | |
string g = guids[i]; | |
string path = AssetDatabase.GUIDToAssetPath(g); | |
//EditorUtility.DisplayProgressBar("Find", "", (float)i / guids.Length); | |
Texture2D tex = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D; | |
if (tex) | |
{ | |
UnityEngine.Debug.Log("path=" + path); | |
UnityEngine.Debug.Log("size=" + GetStorageMemorySize(tex)); | |
UnityEngine.Debug.Log("format=" + tex.format.ToString()); | |
UnityEngine.Debug.Log("path=" + path + ", size=" + GetStorageMemorySize(tex) + ", format=" + tex.format.ToString()); | |
writer.WriteLine(path + "," + GetStorageMemorySize(tex) + "," + tex.format.ToString()); | |
} | |
} | |
//EditorUtility.ClearProgressBar(); | |
writer.Close(); | |
Debug.Log("End"); | |
} | |
public static int GetStorageMemorySize(Texture texture) | |
{ | |
if (mGetStorageMemorySize == null) | |
{ | |
return 0; | |
} | |
var args = new object[] { texture }; | |
int size = (int)mGetStorageMemorySize.Invoke(null, args); | |
return size; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment