Last active
August 29, 2015 14:22
-
-
Save fum1h1ro/a0e0311c5fd41d3f7492 to your computer and use it in GitHub Desktop.
AtlasChecker.cs
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; | |
using System.Collections.Generic; | |
public class AtlasChecker : EditorWindow { | |
struct TexAsset { | |
public string path; | |
public string name; | |
public string guid; | |
} | |
GameObject _object; | |
Dictionary<string, List<TexAsset>> _textures = new Dictionary<string, List<TexAsset>>(); | |
Vector2 _scrollpos = Vector2.zero; | |
[MenuItem("Tools/AtlasChecker")] | |
public static void Checker() { | |
Debug.Log("CHECKER"); | |
AtlasChecker win = (AtlasChecker)EditorWindow.GetWindow(typeof(AtlasChecker)); | |
win.Show(); | |
} | |
void OnGUI() { | |
Rect rc = EditorGUILayout.GetControlRect(GUILayout.Width(192)); | |
GameObject obj = (GameObject)EditorGUI.ObjectField(rc, _object, typeof(GameObject), false); | |
if (obj == null) _object = null; | |
if (obj != null && obj.GetComponent<UIAtlas>() != null) _object = obj; | |
if (_object != null && GUILayout.Button("Search")) { | |
search_textures(); | |
} | |
if (_textures.Count > 0) { | |
dump_textures(); | |
} | |
} | |
void search_textures() { | |
UIAtlas atlas = _object.GetComponent<UIAtlas>(); | |
var sprites = atlas.GetListOfSprites(); | |
_textures.Clear(); | |
foreach (var s in sprites) { | |
//Debug.Log(s); | |
var guids = AssetDatabase.FindAssets(s); | |
for (int i = 0; i < guids.Length; ++i) { | |
var ta = new TexAsset(); | |
ta.guid = guids[i]; | |
ta.path = AssetDatabase.GUIDToAssetPath(ta.guid); | |
ta.name = System.IO.Path.GetFileName(ta.path); | |
if (ta.name == string.Format("{0}.png", s)) { | |
if (!_textures.ContainsKey(ta.name)) _textures[ta.name] = new List<TexAsset>(); | |
_textures[ta.name].Add(ta); | |
} | |
} | |
} | |
} | |
void dump_textures() { | |
_scrollpos = EditorGUILayout.BeginScrollView(_scrollpos); | |
int i = 0; | |
foreach (var key in _textures.Keys) { | |
foreach (var ta in _textures[key]) { | |
if (GUILayout.Button(string.Format("{0}: {1}", i++, ta.path))) { | |
List<Object> objs = Selection.objects.ToList(); | |
objs.Add(AssetDatabase.LoadAssetAtPath(ta.path, typeof(Texture2D))); | |
Selection.objects = objs.ToArray(); | |
} | |
} | |
} | |
EditorGUILayout.EndScrollView(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方 https://twitter.com/fum1h1ro/status/608946440409239552