2D Toolkit Forum
2D Toolkit => Support => Topic started by: test84 on April 17, 2014, 11:10:03 pm
-
Hi,
I need to have two versions of texts for dialog boxes (and preferably buttons), one in English and one in Arabic but I don't need to have them all at the same build. I currently have everything in English and for sake of simplicity of Unicode handling, I will draw text boxes in Photoshop as handling Unicode is hell in Unity, at least as I've researched.
So is there any way to have both of these versions of arts of dialog boxes available and swap them with a change language button? If not, it will still be good enough if I can put a compiler directive or something to let me define which language I want to build for and then have some #IF's in compile time to decide which version to load?
Hope I made myself clear enough, if not, please let me know and I'll put it in another word.
Cheers.
-
No there isn't an official way to do this. You could probably hijack the platform collections feature to handle this, by creating a new platform with 1.0 scale, and a name like @arabic.
tk2dSystem.assetPlatforms is where you'd do this.
I have to reiterate this is officially unsupported though.
-
Thanks. I found how to add a 1x platform but how can I name it?
-
tk2dSystem.assetPlatforms - that array keeps a list of things + names, you can rename "2x" to arabic with scale of 1.0f, that will mean that files ending with @arabic will be treated as a swap.
-
Thanks.
I can't get my head around the platform specific sprite collection for this. I've read the documentation numerous times but can't get it right.
What I don't understand is that we create sprite collections by adding files form different locations to the sprite collection window in Unity and when we change the sprite collection via script, for each sprite it goes to corresponding folder and looks for the one with the designated suffix, i.e. @2x? If it is, then I can't get it to work and please elaborate.
Also does it ever search for @1x?
Thanks.
-
When you set tk2dSystem.CurrentPlatform, any subsequently loaded sprite collections will load that platform. You should ideally do this at the start of the game, and not switch it mid game as it will not reload collections that have already been loaded.
For each sprite in your collection you should have a corresponding platform collection. So if your sprite name is test.png, and your default platform is 1x - you should have test@2x.png if you add a 2x platform. The default platform file can also be test@1x.png. All of this is documented here: http://2dtoolkit.com/docs/latest/advanced/platform_specific_sprite_collections.html
Basically, when you commit this collection - it creates multiple collections in parallel, one for each defined platform. At runtime, it loads the correct collection - it doesn't actually care about source files then.
-
Thanks for the detailed info but I'm afraid to say that I still cannot make it work. Here are steps that I've done:
0- Went inside tk2dSystem.assetPlatforms and renamed 2x to "fa".
1- Created two png files one named "CantEquipMoreThan3PowerUps_Overlay@1x.png" and another called "CantEquipMoreThan3PowerUps_Overlay@fa.png".
1- Created a new sprite collection added support for platforms, and added my "fa" to it.
2- Then I grabbed one of the "CantEquipMoreThan3PowerUps_Overlay@1x.png" to the sprite collection, created a script and in it's start wrote "tk2dSystem.CurrentPlatform = "fa";" and attached it to an empty game object and put it in an empty scene.
3- I run the game and expect it to load the "fa" version automatically, but it shows the default "1x" one.
What am I missing?
-
How many platforms do you have in total?
Does it work if you switch it in the 2D Toolkit preferences panel?
-
I have two, "1x" and "fa".
Yes it does work in preferences panel.
-
If it doesn't change at runtime, it means you're not setting it before the collection loads. You should debug that to work out when its happening.
-
Thanks, changing it in an empty scene that doesn't have any tk2d stuff in it and then transiting to the actual game scene did it.
-
There is a hidden bug that is driving me mad. Sometimes it doesn't work and I just have to restart Unity to make it work. The change of current platform via code seems to either get lost or not affect the sprite collections. I try to edit a lot of things to make it work and it doesn't and I restart Unity and it works. I can't reproduce it to help any further.
-
If Unity thinks an asset has changed it will not unload it, and as a result will not reload it. tk2d doesn't affect it, but it could possibly happen if its committed and not saved - unity defers saving until you quit unity / save another scene, but other things could trigger it too.
The platform switching code in preferences wlil force a reload, but the runtime code behaves exactly like it will at runtime, i,.e. it will not force reload everything thats already loaded. If you want it to force a reload regardless, you have the code, you can switch it around if you like.