Hello,
I was intrigued by this new Localization package and spent a few hours trying to set it up.
my Use case:
I have a random sentence generator, picking 1 sentence in a list, modify it, return it to use it in gameplay and display it.
So I created a StringTable, filling it with my sentences,
and in my code generator class I added a
public UnityEngine.Localization.Settings.LocalizedStringDatabase db;
I load my string table and copy all of its value strings to my List of string form my generator.
(code below)
However, loading the String Database takes me 0.3 seconds,
0.22 if I use the Adressables → groups → use existing builds option
it’s been long since I needed my string, which would should be displayed at the start of the scene.
So, is it an expected behavior of the Localization system, and I used it for the wrong case?
Did I used it incorrectly or did I forgot to check an option?
I found the documentation pretty sparse (had to search on the forum), and do a lot of trial and error.
I don’t understand why I find calls of these methods in OnGUI
methods, as it should be pretty expensive to run.
In the documentation’s screenshots there are reference to “preload” option In LocalizedSettings I cannot find in mine. I suppose it is deprecated, but I would have wanted to preload my strings.
here is my code for loading a complete StringTable into a List of string.
I hope someone could point me on a direction to fix these performance issue,
or that it will be useful to someone who can wait.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class TestLocLoad : MonoBehaviour
{
public UnityEngine.Localization.Settings.LocalizedStringDatabase db;
public List<string> names;
public IEnumerator Start()
{
var d = db.GetTableAsync(db.DefaultTable);
yield return d;
var stringEntryList = d.Result.ToList();
for (int i = 0; i < stringEntryList.Count(); i++)
{
var loc = stringEntryList[i].Value.GetLocalizedString();
names.Add(loc);
}
}
public string getRandomName() => names[Random.Range(0, names.Count)];
}
All of this almost makes me want to restart working on Android apps.