Forum rules - please read before posting.

Font fallback

Hi,

I'm using several fonts in my game and I added Russian localization
For each Unity UI menu I set font asset with Russian font asset as a fallback.

How can I do the same for AC menus?
I noticed they have default\fallback but where can I change it?

Comments

  • edited October 2020

    I don't know what you're referring to by AC menus having "default/fallback". Can you elaborate?

    AC provides a default set of menus, but all have Unity UI variants. It's recommended to rely on Unity UI for your menu rendering.

    With AC for menu rendering, you'd have to change your font through scripting. If you right-click on a Menu Element's Font property in a given Menu, you'll be able to copy an API reference to it. This can be used in a custom script to change the font after e.g. switching to/from the Russian language in your Options menu.

  • edited October 2020

    Thanks for your respond, about "default/fallback" for AC menu:

    When I'm setting font for AC menu and this font (for example -BradBunR) which doesn't support the current language (for example - Russian\Hebrew characters)
    I still see the characters correctly but in different font from what I set. (maybe it's unity fallback...)

    Yes, I'm aware that it's better to rely on Unity UI for menus. most of the menus using that method. But there are few menus which I haven't manage to to convert from AC to Unity UI and still get the exact visual result.
    So, unfortunately I'm stuck with them.

    Your suggestion might solve the issue for Russian but I'm also using Hebrew,
    and RTL isn't support with AC but only with Unity Ui +TextMeshPro component, or am I wrong?

  • edited October 2020

    I still see the characters correctly but in different font from what I set.

    This behaviour is coming from Unity - AC menus rely on OnGUI calls to render text with a given font. If characters are missing, then the result will come from how Unity interprets it.

    So are you looking to change the font when the language changes? If so, you'll need to use scripting to change what font asset is used - but this is easier when using Unity UI because you can do so by attaching components to your Unity UI prefab rather than modifying AC Menu properties which aren't component-based.

    You can change what font is used by a given menu when the menu turns on, or when the language is changed, by hooking into custom events.

    For example, this script - when attached to the base of a Unity UI-based Menu prefab - will update the font of all Unity "Text" components when the menu is turned on, or the font is changed:

    using UnityEngine;
    using UnityEngine.UI;
    using AC;
    
    public class UpdateMenuFont : MonoBehaviour
    {
    
        public Font[] languageFonts = new Font[0];
    
        private void OnEnable ()
        {
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
            EventManager.OnChangeLanguage += OnChangeLanguage;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
            EventManager.OnChangeLanguage += OnChangeLanguage;
        }
    
        private void OnChangeLanguage (int language)
        {
            SetFont (language);
        }
    
        private void OnMenuTurnOn (Menu menu, bool isInstant)
        {
            if (menu.RuntimeCanvas == GetComponent <Canvas>())
            {
                SetFont (Options.GetLanguage ());
            }
        }
    
        private void SetFont (int language)
        {
            Text[] allTexts = Object.FindObjectsOfType <Text>();
            foreach (Text allText in allTexts)
            {
                allText.font = languageFonts[language];
            }
        }
    
    }
    

    (You can adapt it to affect TextMesh Pro Text elements if desired)

    AC supports RTL as a per-language option - just check Reads right-to-left? in the Speech Manager beside your Hebrew language.

  • Thanks Chris, I'm already switching fonts for the Unity UI menus
    using script and TextMeshPro.

    My question was about switching font for AC menus,
    since I have not managed to convert some of them to Unity UI
    and getting the same result.

    Also, in speech settings - Hebrew set to RTL but I don't see any affect
    for AC menus, the characters are still reversed (though, I'm using that property for Unity UI menus and it works well)

    From my understanding probably my best shot will be to convert ALL of the AC menus to Unity UI, so I will post new questions about them in appropriate thread.

  • Though I do recommend using Unity UI for your Menus, an alternative for the OnMenuTurnOn event above - for AC-based Menus - would be:

    private void OnMenuTurnOn (Menu menu, bool isInstant)
    {
        foreach (MenuElement element in menu.elements)
        {
            element.font = newFont;
        }
        menu.Recalculate ();
    }
    

    To be clear about RTL: AC won't reverse the characters themselves, which will have to be imported as reversed into the Speech Manager.

    What it will do, though, is reverse the order of scrolling speech text, and auto-constructed Hotspot sentences, e.g. "Use X on Y" becomes "Y on X Use".

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.