Esempio n. 1
0
    public static void ExecuteLocalize(UILocalize localize, string context)
    {
        if (localize == null)
        {
            return;
        }
        switch (localize.localizeType)
        {
        case UILocalizeType.Text:
            localize.SetText(context);
            break;

        case UILocalizeType.ImageLoad:
            UnityEngine.Sprite sprite = null;
            string[]           paths  = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName("icon.unity3d", context);
            if (paths == null || paths.Length <= 0)
            {
                UnityEngine.Debug.LogError($"{localize.gameObject.name}的语言表id填写错误,找不到对应的sprite资源");
            }
            else
            {
                sprite = AssetDatabase.LoadAssetAtPath <UnityEngine.Sprite>(paths[0]);
            }
            localize.SetImage(sprite);
            break;

        case UILocalizeType.Font:
            UnityEngine.Font font = AssetDatabase.LoadAssetAtPath <UnityEngine.Font>(context);
            localize.SetFont(font);
            break;

        case UILocalizeType.Audio:
            UnityEngine.AudioClip audioClip = AssetDatabase.LoadAssetAtPath <UnityEngine.AudioClip>(context);
            localize.SetAudio(audioClip);
            break;

        default:
            break;
        }
    }