using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class NGuiAtlasHelper : MonoBehaviour
{
class StoredAtlasRefs
{
public UIAtlas replacement;
public Material spriteMaterial;
}
class StoredFontRefs
{
public UIFont replacement;
public Material material;
}
static Dictionary<UIAtlas,StoredAtlasRefs> AtlasDictionary;
static Dictionary<UIFont,StoredFontRefs> FontDictionary;
[MenuItem("NGuiAtlasHelper/Clear References")]
static void ClearRefs()
{
if(AtlasDictionary == null)
{
AtlasDictionary
= new Dictionary
<UIAtlas, StoredAtlasRefs
> (); }
UIAtlas
[] atlases
= (UIAtlas
[])Resources
.FindObjectsOfTypeAll(typeof(UIAtlas
)); foreach (UIAtlas atlas in atlases)
{
if (atlas.replacement != null)
{
Debug.Log(string.Format("atlas: {0} reference: {1} set to null", atlas.name, atlas.replacement.name));
StoredAtlasRefs atlas_ref
= new StoredAtlasRefs
(); atlas_ref.replacement = atlas.replacement;
atlas_ref.spriteMaterial = atlas.spriteMaterial;
AtlasDictionary[atlas] = atlas_ref;
atlas.replacement = null;
atlas.spriteMaterial = null;
}
}
if(FontDictionary == null)
{
FontDictionary
= new Dictionary
<UIFont, StoredFontRefs
> (); }
UIFont
[] fonts
= (UIFont
[])Resources
.FindObjectsOfTypeAll(typeof(UIFont
)); foreach (UIFont font in fonts)
{
if (font.replacement != null)
{
Debug.Log(string.Format("font: {0} reference: {1} set to null", font.name, font.replacement.name));
StoredFontRefs font_ref
= new StoredFontRefs
(); font_ref.replacement = font.replacement;
font_ref.material = font.material;
FontDictionary[font] = font_ref;
font.replacement = null;
font.material = null;
}
}
}
[MenuItem("NGuiAtlasHelper/Restore References")]
static void RestoreRefs()
{
if(AtlasDictionary != null)
{
foreach(KeyValuePair<UIAtlas,StoredAtlasRefs> entry in AtlasDictionary)
{
entry.Key.replacement = entry.Value.replacement;
entry.Key.spriteMaterial = entry.Value.spriteMaterial;
Debug.Log(string.Format("atlas: {0} reference: {1} restored", entry.Key.name, entry.Key.replacement.name));
}
AtlasDictionary = null;
}
if(FontDictionary != null)
{
foreach(KeyValuePair<UIFont,StoredFontRefs> entry in FontDictionary)
{
entry.Key.replacement = entry.Value.replacement;
entry.Key.material = entry.Value.material;
Debug.Log(string.Format("Font: {0} reference: {1} restored", entry.Key.name, entry.Key.replacement.name));
}
FontDictionary = null;
}
}
}