Hello Guest

Author Topic: ScriptableObject for sprite reference  (Read 3413 times)

Majicpanda

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 62
    • View Profile
ScriptableObject for sprite reference
« on: September 09, 2013, 05:24:45 am »
I want to use ScriptableObjects for my monsters in my game so that I can load up the data from them.  The issue I can't seem to figure out is how to get the sprite to show up in the inspector besides just using a public tk2dSpriteCollectionData monsterData ref to my monster atlas and then do a workflow that all monster names exactly match a sprite in the data and do SetSprite(monsterData, monsterName), but I was hoping for something a bit more concrete and not error prone.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: ScriptableObject for sprite reference
« Reply #1 on: September 09, 2013, 11:27:39 am »
Create a custom editor (inspector) for your scriptable object, then for the sprite collection data / spriteId pair, use something like this:
Code: [Select]
tk2dSpriteGuiUtility.SpriteSelector( targetSprites[0].Collection, targetSprites[0].spriteId, spriteChangedCallbackInstance, null );

Refer to tk2dSpriteEditor for more details on the additional requirements (spriteChangedCallbackInstance) for this.