I am using Unity 2020 and the Localization package.
I use the localization to give a language specific url to a youtube player.
But I guess the URL is not working. Anyone know why?
The youtube player in general is working.
using UnityEngine;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.Localization.Settings;
using Vuplex.WebView;
class TutorialView : MonoBehaviour {
CanvasWebViewPrefab _canvasWebViewPrefab;
string url;
void Start() {
setLocalUrl("Tutorial", "TUTORIAL_URL");
var canvas = GameObject.Find("Canvas");
// Create a CanvasWebViewPrefab
// https://developer.vuplex.com/webview/CanvasWebViewPrefab
_canvasWebViewPrefab = CanvasWebViewPrefab.Instantiate();
_canvasWebViewPrefab.transform.SetParent(canvas.transform, false);
_canvasWebViewPrefab.Initialized += (sender, eventArgs) => {
_canvasWebViewPrefab.WebView.LoadUrl(url);
};
}
void setLocalUrl(string key, string url) {
AsyncOperationHandle<string> op = LocalizationSettings.StringDatabase.GetLocalizedStringAsync(key, url);
if (op.IsDone) {
url = op.Result;
} else {
op.Completed += (o) => url = o.Result;
}
}
}
Does Completed get called? What is the value of result?
Everything looks fine so there must be something wrong with the setup that I can not see from the screenshots. Can you try creating a simple project and see if it happens in that?
I have no clue if it never finishes or it is empty. But “Result” is not printed on the console.
The code keeps running and url is not changed with the localized string.
I am running Unity on windows. The target plattform is android for the VR headset Oculus Quest.
EDIT: I added “op.WaitForCompletion(); // Force synchronous loading”.
Now it sets the right URL.