Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Real World on April 16, 2015, 06:18:10 AM
-
I'm trying to setup a system for swapping the font used by all labels in my game based on the current language. I've created a font reference object and assigned it to all my labels. Should this font reference exist in the scene or as a prefab?
If I make it a prefab I can't alter the font the font reference points to at runtime.
If I add it to the scene then any UI labels that exist as prefabs and are added to my UI at runtime can't maintain a reference to the font reference object because prefabs don't know about objects in my scene.
-
Exist in the scene? No. But it should be a prefab, yes. Instead of 1 prefab like you had before, you would have 2 font prefabs -- one would be a real one, the other one would simply reference the first. All labels would be using the second (reference) font.
To load it at run-time, place the prefab in Resources folder and use Resources.Load, or just reference it from some script that exists in your scene. In other words -- same as any other Unity prefab.
-
Not sure I understand you, or maybe you have misunderstood me. Here's what I have:
PREFABS:
- UIFont - English
- UIFont - Japanese
- UIFont (reference) - pointing to English
- UILabel - font is set to UIFont (reference)
So at run time I create an instance of my UILabel prefab. The font is correctly set to English but I have no way to change that to Japanese as my font reference is a prefab and I can't modify a prefab at run time, only an instance of one.
-
You can modify it, but you need to Resources.Load it first -- so it needs to be in the Resources folder along with others.
Resources.Load it, GetComponent<UIFont>() and set it to point to another.