/// <summary> /// Draw a sprite selection field. /// </summary> static public void SpriteField(string fieldName, string caption, UIAtlas atlas, string spriteName, SpriteSelector.Callback callback) { GUILayout.BeginHorizontal(); GUILayout.Label(fieldName, GUILayout.Width(76f)); if (atlas.GetSprite(spriteName) == null) { spriteName = ""; } if (GUILayout.Button(spriteName, "MiniPullDown", GUILayout.Width(120f))) { SpriteSelector.Show(atlas, spriteName, callback); } if (!string.IsNullOrEmpty(caption)) { GUILayout.Space(20f); GUILayout.Label(caption); } GUILayout.EndHorizontal(); }
/// <summary> /// Convenience function that displays a list of sprites and returns the selected value. /// </summary> static public void AdvancedSpriteField(UIAtlas atlas, string spriteName, SpriteSelector.Callback callback, bool editable, params GUILayoutOption[] options) { // Give the user a warning if there are no sprites in the atlas if (atlas.spriteList.Count == 0) { EditorGUILayout.HelpBox("No sprites found", MessageType.Warning); return; } // Sprite selection drop-down list GUILayout.BeginHorizontal(); { if (GUILayout.Button("Sprite", "DropDownButton", GUILayout.Width(76f))) { SpriteSelector.Show(atlas, spriteName, callback); } if (editable) { if (!string.Equals(spriteName, mLastSprite)) { mLastSprite = spriteName; mEditedName = null; } string newName = GUILayout.TextField(string.IsNullOrEmpty(mEditedName) ? spriteName : mEditedName); if (newName != spriteName) { mEditedName = newName; if (GUILayout.Button("Rename", GUILayout.Width(60f))) { UISpriteData sprite = atlas.GetSprite(spriteName); if (sprite != null) { NGUIEditorTools.RegisterUndo("Edit Sprite Name", atlas); sprite.name = newName; List <UISprite> sprites = FindAll <UISprite>(); for (int i = 0; i < sprites.Count; ++i) { UISprite sp = sprites[i]; if (sp.atlas == atlas && sp.spriteName == spriteName) { NGUIEditorTools.RegisterUndo("Edit Sprite Name", sp); sp.spriteName = newName; } } mLastSprite = newName; spriteName = newName; mEditedName = null; NGUISettings.selectedSprite = spriteName; } } } } else { GUILayout.BeginHorizontal(); GUILayout.Label(spriteName, "HelpBox", GUILayout.Height(18f)); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { NGUISettings.selectedSprite = spriteName; Select(atlas.gameObject); } } } GUILayout.EndHorizontal(); }
/// <summary> /// Draw a sprite selection field. /// </summary> static public void SpriteField(string fieldName, UIAtlas atlas, string spriteName, SpriteSelector.Callback callback) { SpriteField(fieldName, null, atlas, spriteName, callback); }