Hello Guest

Author Topic: Loading Collections and Platform Support.  (Read 12021 times)

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Loading Collections and Platform Support.
« on: December 03, 2013, 09:41:26 pm »
Hi,
I have noticed some issues with trying to create sprites at runtime and dealing with platform support. I remember testing this a while ago, so I think its a relatively new thing. The only way I can get hd graphics to show up is to have a sprite already instantiated in the editor and to leave its collection data alone.

here is the code that I am using to set the sprites at run time. The first modifies a test sprite in the scene, and the next adds a tk2dsprite to an empty game object and then sets its sprites. both of these show up as the standard graphic(i drew SD and HD on the graphics so that i would know), and the one that uses the same collection, but is not touched by code shows up as HD.

Code: [Select]
               // Load the sprite collection data
tk2dSpriteCollectionData data = tk2dSystem.LoadResourceByName<tk2dSpriteCollectionData>("dataName");

// Set the sprite with the loaded data.
_testSprite.SetSprite(data, "CardBack");

// Add a sprite component and then set the sprite
tk2dSprite testSprite1 =  _testGameObject.AddComponent<tk2dSprite>();
testSprite1.SetSprite(data, "CardBack");

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #1 on: December 03, 2013, 11:16:36 pm »
Would it be possible to create/email a repro case for this to support at unikronsoftware.com?

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #2 on: December 03, 2013, 11:26:35 pm »
Unfortunately I will have to ask a little higher up the food chain to get you that repo, but I can tell you the temporary fix that I have found. I noticed that the data it was loading didn't have any platform data. This got me looking at the data prefabs in the editor. I noticed that when you have platform support the managed data prefabs are checked as loadable, and the shared one with the platform data was not checked off as loadable. I unchecked loadable on the sub data prefabs and made the root data prefab loadable and set the asset name. This fixed the problem and allowed that collection to show up with hd in all 3 examples.

I think the problem was that since both of the sub data collections were checked as loadable, and named the same thing, resources would just load the first one it found which would be the 1x version. Will this help enough or should I get to work on trying to get a repo together?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #3 on: December 04, 2013, 12:09:57 am »
If thats the case, then the 1x & 2x assets shouldn't be in a resources directory. You shouldn't need to load them explicitly, and the tk2d resource system handles that transparently when needed.

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #4 on: December 04, 2013, 12:19:29 am »
None of the collections or data are in the resources directory. The collections swap out fine when they are inside a prefab or instantiated in the scene. Unless I manually go into the data and swap around which collections are considered loadable the tk2dSystem.LoadResourceByName function always grabs the 1x version of that data instead of the root data that i'm guessing it should.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #5 on: December 04, 2013, 11:08:46 am »
Sorry, I misread the code snippet in the first part. You should never load the 1x / 2x assets explicitly. You should always load the main sprite collection data object - one way to guarantee you're loading the right thing is to load using the guid. You can work out what it is from the index object

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #6 on: December 04, 2013, 03:12:47 pm »
Ok, However the reason for loading the collections manually is because our game is built to have the art "Swapped" based on a theme. At runtime we have access to the theme name so we append that with a suffix to get the correct collection. Is there a way to turn this into the correct GUID?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #7 on: December 04, 2013, 03:49:40 pm »
The collection itself isn't put in the loadable list by default.
ABCollection (not loadable)
   ABCollection@1x (managed, loadable)
   ABCollection@2x (managed, loadable)

If you put ABCollection (just the data object) into a resources directory, you will be able to use Resources.Load(...) to load just that.

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #8 on: December 04, 2013, 04:06:56 pm »
That was the solution that we used on a previous project, however It leads to some confusion and issues. First off if someone doesn't commit correctly across version control some times we have to delete the managed data and remake the collection in the editor. This then pops the 1x and 2x stuff down into resources. It also just allows more area's where things can stop working because things are in the wrong place. We can change this, but were hoping that it would be possible to avoid this and just use the tk2d loading system. If the loading is working as intended, will changing the "ABCollection (not loadable)" to being loadable instead of the 1x and 2x cause major issues?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #9 on: December 04, 2013, 04:51:16 pm »
1x & 2x will need to be loadable for the system to be able to pick the correct one to load. It is possible to make this work with the loadable system, just that it isn't tested thoroughly enough to support as "feature". You shouldn't make the others unload able, but perhaps add something to the build to set the names differently to avoid random name collisions.

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #10 on: December 04, 2013, 05:13:49 pm »
Am I correct in assuming that tk2d behind the scenes just uses the GUID to load everything when dealing with platforms? If so that changing the 1x and 2x collection asset names to have 1x and 2x shouldn't break anything. Then all I need to do is make it so that the root data prefab is loadable and has the correct asset name it will work.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #11 on: December 04, 2013, 05:21:24 pm »
It uses guids to load them. Changing asset names shouldn't break it, but it hasn't been tested.

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #12 on: December 04, 2013, 05:38:48 pm »
Ok, I will let you know if it causes any issues.

Dreamkind

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #13 on: December 04, 2013, 08:33:28 pm »
I am having trouble finding a place to make the collection automatically make the non 1x or 2x collection be loadable. I have looked through the sprite collection builder, but I can't figure out why this data prefab is marked loadable for collections with out platform data, but then not marked as loadable with platform data.

The closest I can figure out is that the function tk2dSystemUtility.UpdateAssetName(gen.spriteCollection, gen.assetName); On line 1389 makes is where the non platform data is made loadable, but for some reason if it has platform data this function does not make it loadable. We have somewhere around 25 sprite collections and I would rather not have to go through all of them every time I make a build.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading Collections and Platform Support.
« Reply #14 on: December 04, 2013, 10:37:58 pm »
Ok what is the status of everything right now? I don't think I see the entire picture here.
For each sprite collection with platform data (1x, 2x) you'll have 2 corresponding entries in tk2dSystem. You can verify this by looking through Resources/tk2d_??? in there. The asset names should be empty on the 1x and 2x assets. If yours aren't empty strings - how did that happen?

Next - if you tick "Loadable asset" on the main sprite collection + commit, you should see one more entry in tk2dSystem. This one should have the asset name in there. If you load by name, this is what you should get.

What do you see in your setup?