Forum rules - please read before posting.

Separate fonts for different languages?

I'm considering translating my game to other languages, and I wonder if there's a workaround to have different fonts for different languages? 

I'm using standard AC menus and subtitles, and a custom-made pixel font for latin letters. If I would to be implementing chinese or arabic support I would need to use other fonts, and wonder if this is feasible to implement.

Comments

  • It is, but you'd have to do it through script by manually changing the font variable of each MenuElement class inside each Menu.  Something like:

    // Get all menus
    List<AC.Menu> allMenus = AC.PlayerMenus.GetMenus ();

    // Iterate through each menu
    foreach (AC.Menu menu in allMenus)
    {
      // Iterate through each menu's elements
      foreach (AC.MenuElement element in menu.elements)
      {
        element.font = myNewFont;
      }
    }


    You can attach this to a custom event named OnChangeLanguage
  • Great! I've fiddled with your example and I'm able to change the font by calling a function based on your code. 

    However, I don't understand how I can attach this to a custom event that kicks in when OnChangeLanguage is changed. Do I use an OnEnable function, or how does that work?

    Thanks again!
  • See the tutorial I linked to above: http://www.adventurecreator.org/tutorials/calling-custom-events

    Use an OnEnable function if you want this to work from any time - as it'll register when the scene begins.  OnEnable/OnDisable is what you generally want unless you ever want to use an event selectively.

    Note that this won't cause the code to run when the scene begins, just that it can do - the code will be called whenever the language option is changed.
  • One other thing: this event won't run when AC begins - only when the language is changed explicitly by the player in your Options Menu.  This is because the language will already be set from its PlayerPrefs language - so if the language is changed, and the game restarted, the Menus will still be in their original state.

    To get around this, place the same code in a custom Action, and insert that into an ActionList asset that's set to run when the game begins (assigned via the Settings Manager).  You could actually then remove the code from the custom event, and simply have the event run this ActionList (though be sure to set the ActionList's When running field to Run In Background):

    myActionListAsset.Interact ();
  • Thanks for this! I got this pretty much up and running, but noticed that Unity automatically falls back to supporting non-latin letters for letters not in the font you're using, so no need to change fonts to support Simplified Chinese :)
  • edited December 2021

    Sorry for raising this thread I thought I had it in the bag. But having an issue.
    I don't see any font change when I run this based on your script Chris. trying to change font to Chunkfive as a test. Tried to specifically load the font and tried to publicly declare it the inspector.

    public class ChangeFont : MonoBehaviour
    {

    public Font myNewFont;
    
    void SetNewFont()
    {
        // Get all menus
        List<AC.Menu> allMenus = AC.PlayerMenus.GetMenus();
    
        // Iterate through each menu
        foreach (AC.Menu menu in allMenus)
        {
            // Iterate through each menu's elements
            foreach (AC.MenuElement element in menu.elements)
            {
                element.font = myNewFont;
                //element.font = Resources.Load<Font>("Fonts/Chunkfive");
                Debug.Log("font set"  );
            }
        }
    }  
    

    }

    Console shows font set but no font change occurs.
    All menus are Uinty UI in scene based. Calling this method with Object Send message.
    Using Unity 2021.1.6f1 , AC 1.73.3
    What am I missing?

  • The original issue in this thread was related to AC-menus, so the script works by updating an element's font variable - which is read only by such menus.

    For Unity UI menus, it's necessary to update the Text component itself.

    A script for this can be found on the AC wiki here:
    https://adventure-creator.fandom.com/wiki/Per-language_Menus

  • Thank you Chris. I saw that script long ago and forgot about it :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.