2D Toolkit Forum

2D Toolkit => Support => Topic started by: esdot on September 28, 2014, 04:52:16 pm

Title: Is it possible to access all SpriteCollecitons at runtime?
Post by: esdot on September 28, 2014, 04:52:16 pm
Is there an API to access all shared SpriteCollections at runtime?

We're trying to implement pallette swapping in our game, using a Shader. Like full 4-color pallette swaps, ala GameBoy Color. So, depending on the Level Loaded, I need to pass some parameters to the material for each spriteCollection.

If I try and set material properties on a specific sprite, the Material gets reverted back to the original, whenever UpdateMaterials() is called in tk2dSprite.

So, what I need to do is access the array of SharedMaterials that tk2d is using, and make my material.SetColor() calls there.

Is there an API to do that? I found ann array of AllCollections them in tk2dSpriteGuiUtility, but it's not accessible in my runtime code. I realize I could probably make a sprite, and change it's sprite collection manually, or link a prefab of each type of sprite, but both of those are pretty hacky.
Title: Re: Is it possible to access all SpriteCollecitons at runtime?
Post by: unikronsoftware on September 28, 2014, 07:50:40 pm
No, there is no way to do something like this out of the box in Unity. There isn't a way to dynamically load something in Unity aside from asset bundles and resources.load, both of which require different workflows and files to be stored in specific places.
Title: Re: Is it possible to access all SpriteCollecitons at runtime?
Post by: esdot on September 28, 2014, 08:42:51 pm
Ok cool, I got it working pretty great by just creating a SpriteCollections script, and linking each SpriteCollectionData prefab by hand.

Works awesome!
Title: Re: Is it possible to access all SpriteCollecitons at runtime?
Post by: unikronsoftware on September 28, 2014, 09:15:02 pm
It probably isn't immediately obvious, but that will load every single sprite collection + all associated textures you have referenced in that script. Its perfectly fine if you meant to have them loaded anyway, but otherwise you might be quickly eating into your memory budget.
Title: Re: Is it possible to access all SpriteCollecitons at runtime?
Post by: esdot on September 29, 2014, 10:17:45 pm
Ya should be fine. One of the benefits of doing Pixel Art, all our 8 sprite collections combined fit in a single 1024x2048 texture :)