Author Topic: NGUI Editor Sprite Name Selection  (Read 3131 times)

Quarkism

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
NGUI Editor Sprite Name Selection
« 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?
« Last Edit: June 14, 2013, 04:25:32 PM by Quarkism »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Editor Sprite Name Selection
« Reply #1 on: June 14, 2013, 04:53:31 PM »
SpriteSelector.Show

Quarkism

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 48
    • View Profile
Re: NGUI Editor Sprite Name Selection
« Reply #2 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.