Hello Guest

Author Topic: Add a sprite picker to another component in the inspector?  (Read 3896 times)

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Add a sprite picker to another component in the inspector?
« on: November 08, 2013, 11:58:22 pm »
I want to write a class that refers to a tk2dSprite by collection and name, and ideally I'd like it to show up in the editor with the same picker utility that exists for the tk2dSprite class. 

I could just point my class at instances of tk2dSprite GameObjects but I'm looking for the more fancy editor solution.  I also don't really want to create a ton of GameObjects in the hierarchy specifically so I can draw lines to them -- I'd rather my data structure show the thing it refers to immediately in the inspector.

Is there a fast and easy way to do this?  I started trying to pick apart the tk2dSpriteEditor code but it's late Friday afternoon and I'm not super engaged at the moment :)

Thanks, have a great weekend!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Add a sprite picker to another component in the inspector?
« Reply #1 on: November 09, 2013, 09:52:01 am »
Its fairly straightforward.

This line draws the sprite picker
Code: [Select]
tk2dSpriteGuiUtility.SpriteSelector( currentCollection, currentSpriteId, SpriteChangedCallbackImpl, null );
It uses a callback to assign the sprite when switched:
Code: [Select]
void SpriteChangedCallbackImpl(tk2dSpriteCollectionData spriteCollection, int spriteId, object data)
{
              // sprite changed, assign here
}