Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Quarkism on June 14, 2013, 01:50:12 PM

Title: NGUI Editor Sprite Name Selection
Post by: Quarkism on June 14, 2013, 01:50:12 PM
I have a inventory system. Each item in the system has a monobehaviour attached where I define the item's properties and functionality. Currently one of the fields (the Icon field) is a Texture2D.

I am using the MvvM pattern. This means that my inventory item script does not draw itself and includes no UISprite's or widgets. Instead I have a second game object (the view) and use binders to set the value of the visual components (currently the icon binds to a UITexture) as defined by the inventory item.

My solution currently works fine, but I would like to define my icons using an Atlas and UISprite instead.

I noticed that in the editor for the UISprite behaviour you have a very nice Atlas and Sprite inspector. Being that manually typing in the 'name' of the sprite is a horrible solution, I would like to include this sprite selector in my inventory item script. Where is this code for this?
Title: Re: NGUI Editor Sprite Name Selection
Post by: ArenMook on June 14, 2013, 04:53:31 PM
SpriteSelector.Show
Title: Re: NGUI Editor Sprite Name Selection
Post by: Quarkism on June 14, 2013, 06:13:08 PM
Thanks, got it working. I forgot that editor scripts get placed in a separate assembly, but your suggestion led me to them !.

Here is the functional code in case anyone cares.

  1.    
  2.   public override void OnInspectorGUI()
  3.     {
  4.         EditorGUIUtility.LookLikeControls(80f);
  5.  
  6.         const float iconSize = 64f;
  7.  
  8.         ComponentSelector.Draw(Equipment.Atlas, OnSelectAtlas);
  9.  
  10.         if (Equipment.Atlas != null)
  11.         {
  12.             NGUIEditorTools.AdvancedSpriteField(Equipment.Atlas, Equipment.Sprite, SelectSprite, false);
  13.         }
  14.