Localization carrousel

I have been testing this localization system and I created a utility that could be fit in it.

This code can be used to create a carrousel of LocalizedString to show in places where the localized resource must change. This is used with string, but it could be interesting to implement with all the LocalizedReference implementations like assets.

With the LocalizedCarrousel you can have a list of LocalizedString in dialogues and pass to the next when you call next(). Can check if the carrousel has more elements and get the actual LocalizedString.

Maybe something like this could be interesting to add in future releases. Im not a experienced user in Unity, becouse that, it could be a lot of coding errors about the lifecycle of Unity or programming standars.

public class LocalizedCarrousel : LocalizeStringEvent
{
    public LocalizedString[] dialogues;
    private int index;

    public LocalizedCarrousel() : base()
    {
        index = 0;
    }

    public void next()
    {
        if (hasNext())
        {
            StringReference = dialogues[index];
            index++;
        }
    }

    public LocalizedString getActual()
    {
        return dialogues[index];
    }

    public bool hasNext()
    {
        return index < dialogues.Length;
    }

    private void Update()
    {
        if (Input.GetKeyDown("a"))
        {
            next();
        }
    }
}

The attached file contains an image of how it is shown in the Unity Editor.

6757576--779971--Captura.PNG

1 Like

Thanks. I can probably put it into the scripting docs or sample code.