Skip to content

Instantly share code, notes, and snippets.

@fum1h1ro
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fum1h1ro/a0e0311c5fd41d3f7492 to your computer and use it in GitHub Desktop.
Save fum1h1ro/a0e0311c5fd41d3f7492 to your computer and use it in GitHub Desktop.
AtlasChecker.cs
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();
}
}
@fum1h1ro
Copy link
Author

@fum1h1ro
Copy link
Author

複数選択に対応

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