Unity本地化:添加多语言支持

文档:Quick Start Guide | Localization | 1.2.1 (unity3d.com)

Unity本地化:添加多语言支持_第1张图片Unity本地化:添加多语言支持_第2张图片

 

/****************************************************
    文件:LocaleSelector.cs
    作者:Edision
    日期:#CreateTime#
    功能:语言本地化
*****************************************************/

using System.Collections;
using UnityEngine;
using UnityEngine.Localization.Settings;
 
public class LocaleSelector : MonoBehaviour 
{
    private bool active = false;

    private void Start()
    {
        int ID = PlayerPrefs.GetInt("LocaleKey", 0);
        ChangeLocale(ID);
    }

    public void ChangeLocale(int localeID)
    {
        if (!active)
        {
            StartCoroutine(SetLocale(localeID));
        }
    }

    private IEnumerator SetLocale(int _localID)
    {
        active = true;
        yield return LocalizationSettings.InitializationOperation;
        LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.Locales[_localID];
        PlayerPrefs.SetInt("LocaleKey", _localID);
        active = false;
    }

}

 

你可能感兴趣的:(学习记录,unity,游戏引擎,c#)