- Home /
Finding all text labels in a scene
Hi,
In an effort to localise a game which is being published for iOS and Android, I'd like to get all of the strings from the CMS.
The best possible way I can see this working, is naming my labels with something like "COPY_TITLE", "COPY_DESCRIPTION", "COPY_INTRO", and so on. These labels could then have whatever values at build time, but then at runtime, when we get new values from the CMS, I'd my initial setup to just iterate through every single label in the scene, active or non-active, and see if its name contains "COPY_". If so, find the matching value to that key, in the data received from the CMS.
Is there a way of doing this, or perhaps a different/better way of going about it?
I'm using Unity 5 PRO, if it helps.
Thanks
Answer by DoTA_KAMIKADzE · Jun 17, 2015 at 01:05 AM
By labels you mean the GUI.Label or UI Text or ...? If UI Text, then what you want is this:
Text[] yourLabels = FindObjectsOfType<Text>();
foreach (Text someLabel in yourLabels)
{
//do here whatever you need
}
If you're using GUI.Label then you could simply use your source of strings directly? E.g. if it would be a list/array:
GUI.Label(new Rect(10, 10, 100, 20), yourSourceOfStrings[4]);//or whichever one this label should be using
As for the different/better way I'd suggest you firstly to go through FREE Localizations out THERE and check their code, maybe you wouldn't even want to do your own localization after that in first place.
That's perfect. It was for UI text, so the 1st one worked great. Thanks
Is there a way to search the scene for all objects that are assets with a certain label? I'm trying to search l:Dynamic for objects that have the Dynamic tag but it only finds in the project, not in the scene.
Your answer
Follow this Question
Related Questions
Modifying line order in UI Text component 0 Answers
How do I use custom input validation on an InputField? 1 Answer
Get Position of a specific letter in UI Text containing line breaks 0 Answers
Add asset to array during runtime 0 Answers
If i have a script how to I input an int from there to a text UI? 1 Answer