Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: magicpotato on November 21, 2013, 03:55:50 AM
-
Hello,
When I change a atlas that don't have the sprite old one,
The inspector will broken.
You can reference and fix it.
// UISpriteInspector.cs.
void OnSelectAtlas (Object obj)
{
serializedObject.Update();
SerializedProperty sp = serializedObject.FindProperty("mAtlas");
sp.objectReferenceValue = obj;
serializedObject.ApplyModifiedProperties();
UISprite sprite = target as UISprite;
sprite.ValidateSprite();
}
// UISprite.cs
public void ValidateSprite()
{
if (!string.IsNullOrEmpty(mSpriteName))
{
if (mAtlas != null && atlas.GetSprite(mSpriteName) == null && mAtlas.spriteList.Count > 0)
{
Debug.LogWarning("** CAN'T FIND SPRITE: " + mSpriteName);
SetAtlasSprite(mAtlas.spriteList[0]);
}
}
}
-
That's better
// UISpriteInspector.cs
public override void OnPreviewGUI (Rect rect, GUIStyle background)
{
UISprite sprite = target as UISprite;
if (sprite == null || !sprite.isValid) return;
Texture2D tex = sprite.mainTexture as Texture2D;
if (tex == null) return;
UISpriteData sd = sprite.atlas.GetSprite(sprite.spriteName);
if (sd == null)
{
sprite.ValidateSprite();
sd = sprite.atlas.GetSprite(sprite.spriteName);
}
NGUIEditorTools.DrawSprite(tex, rect, sd, sprite.color);