这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

39 行
1.4 KiB

using UnityEngine;
using UnityEngine.Localization;
namespace UnityEditor.Localization.Samples
{
/// <summary>
/// This sample shows how to use the LocalizedString ChangeHandler to get a notification whenever a new translated string is available.
/// This method is suited to dealing with static strings that will not change during game play for the selected Locale.
/// </summary>
public class LocalizedStringWithChangeHandlerExample : MonoBehaviour
{
// A LocalizedString provides an interface to retrieving translated strings.
// This example assumes a String Table Collection with the name "My String Table" and an entry with the Key "Hello World" exists.
// You can change the Table Collection and Entry target in the inspector.
public LocalizedString stringRef = new LocalizedString() { TableReference = "My String Table", TableEntryReference = "Hello World" };
string m_TranslatedString;
void OnEnable()
{
stringRef.StringChanged += UpdateString;
}
void OnDisable()
{
stringRef.StringChanged -= UpdateString;
}
void UpdateString(string translatedValue)
{
m_TranslatedString = translatedValue;
Debug.Log("Translated Value Updated: " + translatedValue);
}
void OnGUI()
{
GUILayout.Label(m_TranslatedString);
}
}
}