playMaker

Author Topic: Change all button images on change of language  (Read 2451 times)

unclesniffy

  • Playmaker Newbie
  • *
  • Posts: 3
Change all button images on change of language
« on: May 29, 2017, 01:54:49 AM »
I have around 100 buttons in my app, what would be the best way to change all the images on the buttons when the user selects a different language?

I would think having all the images named the same, but in different folders; ie

English
Japanese
German

and then change the path to the image as the language changes, ie;

Assets/images/German/button1.jpg

But I cant figure out any way to change the Source Image sprite as a string variable...

Any ideas?  :)

« Last Edit: May 29, 2017, 02:14:17 AM by unclesniffy »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Change all button images on change of language
« Reply #1 on: May 29, 2017, 05:48:26 AM »
Well, i think your concept is not good in the first place. Why are you using images for text? You should render an empty button and just change the text.

Since you're already doing it like that, you can consider using the swap sprite action by our dear djaydino.
Available for Playmaker work

unclesniffy

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Change all button images on change of language
« Reply #2 on: May 29, 2017, 08:08:21 PM »
The buttons are designed graphically rather than just being a case of a blank button with standard text on. That would be so much easier!  ;D

Have had a look at swap sprite, but that uses an object variable, so it's not easy to set up a folder for the images to look at.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Change all button images on change of language
« Reply #3 on: May 30, 2017, 04:43:48 AM »
Oh, you want them pulled from a folder. Maybe try storing everything into separate arrays and then just pull them from the array? Each language would be one array.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Change all button images on change of language
« Reply #4 on: May 30, 2017, 05:40:52 PM »
Hi,
I would go for arrays also, as Krmko said one for each language and also one array with your button objects. and you can loop thru to set it up.
if you want i can make a quick sample how to set this up.

If you are using ugui and you have the ugui proxy full package from the Ecosystem, you can use uGuiImageSetSprite instead of swap sprite :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Change all button images on change of language
« Reply #5 on: May 31, 2017, 02:11:07 AM »
Hi,

 you can also use Resources, which means you only load in memory the images you need whereas arrays would mean loading all images for all languages.

 Use LoadResource from the Ecosystem, you can get sprites from this I think, else you rawImage for your UI element and have the images as textures, not sprites.

 Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Change all button images on change of language
« Reply #6 on: June 01, 2017, 08:23:01 PM »
Hi jean,
I haven't worked with Resources yet.
Could you explain how you would set this up?
I would like to add this to my inventory tutorial, using json or xml
But i can't seem to get a sprite variable from a sliced sprite sheet.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Change all button images on change of language
« Reply #7 on: June 05, 2017, 04:08:53 AM »
Hi,

Resources is a special Folder where you can put assets, they will be added as files in your build, but they will not be loaded in memory by default, you will need to request them.

Use LoadResource from the ecosystem to do so. More info here:

https://unity3d.com/learn/tutorials/temas/best-practices/resources-folder
https://docs.unity3d.com/ScriptReference/Resources.html

now, to get a sprite from a sliced spriteSheet, I think it's tricky, I recall having struggled with this in the past. Could you pm me with your spriteSheet and what you want to extract, I'll give it a go.

Bye,

 Jean