Created
March 2, 2017 08:42
-
-
Save EsProgram/3f0d5b2f9287787ee22d1284297ec203 to your computer and use it in GitHub Desktop.
UnityでTextureのAssetBundleを確認するWindow
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.Linq; | |
using System.Collections; | |
public class BundleTextureWindow : EditorWindow | |
{ | |
static EditorWindow window; | |
Texture[] texs; | |
Vector2 scroll; | |
const int ButtonHeight = 50; | |
[MenuItem("Custom/Bundle Texture")] | |
public static void Open() | |
{ | |
window = GetWindow<BundleTextureWindow>("Bundle Texture"); | |
} | |
void OnGUI() | |
{ | |
//AssetBundleを選択するダイアログを開く | |
if(GUI.Button(new Rect(0, 0, window.position.size.x, ButtonHeight), "Open")) | |
{ | |
//Bundleのパスを取得する | |
var path = EditorUtility.OpenFilePanel("Select Bundle", Application.dataPath, "unity3d"); | |
if(path.Length != 0) | |
{ | |
var bundle = AssetBundle.LoadFromFile(path); | |
//AssetBundleからTextureをロード | |
texs = bundle.LoadAllAssets<Texture>(); | |
bundle.Unload(false); | |
} | |
} | |
//取得したAssetBundleからTextureがロード出来た場合に、Textureを表示する | |
if(texs != null) | |
{ | |
int h = 0; | |
int hmax = 0; | |
int vmax = 0; | |
for(int i = 0; i < texs.Length; ++i) | |
{ | |
hmax += texs[i].height; | |
vmax = vmax < texs[i].width ? texs[i].width : vmax; | |
} | |
scroll = GUI.BeginScrollView(new Rect(0, ButtonHeight, window.position.size.x, window.position.size.y - ButtonHeight), scroll, new Rect(0, 0, vmax, hmax)); | |
for(int i = 0; i < texs.Length; ++i) | |
{ | |
h += texs[i].height; | |
GUI.DrawTexture(new Rect(0, i * h, texs[i].width, texs[i].height), texs[i]); | |
} | |
GUI.EndScrollView(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment