Unity多语言转换工具

本文介绍了一种方法,通过遍历Unity场景和Prefab中的Text组件,提取并导出Json文件来实现多语言转换。用户可以对Json进行翻译后,使用专用工具将翻译内容批量替换回原游戏资源,从而实现Unity游戏的多语言支持。
摘要由CSDN通过智能技术生成

说明

遍历Unity场景和Prefab,提取Text组件文字,并导出Json表。可将Json文本进行多语言翻译后,利用工具将内容替换回原场景或Prefab。

代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class ChangeTextLanguageTool : MonoBehaviour
{
   
    [ExecuteInEditMode]
    [MenuItem("LanguageTool/一键提取Prefab中文字")]
    private static void GetAllPrefab()
    {
   
        LoadPath(Application.dataPath);
    }

    static void LoadPath(string path)
    {
   
         TextData _temData = new TextData();
        string genPath = path;
        string[] filesPath = Directory.GetFiles(genPath, "*.prefab", SearchOption.AllDirectories);
        for (int i = 0; i < filesPath.Length; i++)
        {
   
            PrefabData _tempPrefab = new PrefabData();
            filesPath[i] = filesPath[i].Substring(filesPath[i].IndexOf("Assets"));
            GameObject _prefab = AssetDatabase.LoadAssetAtPath(filesPath[i], typeof(GameObject)) as GameObject;

            GameObject prefabGameobject = PrefabUtility.InstantiatePrefab(_prefab) as GameObject;
            _tempPrefab.PrefabName = prefabGameobject.name;

            Text[] _tempAllText = prefabGameobject.transform.GetComponentsInChildren<Text>(true);
            for (int j = 0; j < _tempAllText.Length; j++)
            {
   
                if (!string.IsNullOrEmpty(_tempAllText[j].text))
                {
   
                    TextItemData _tempItemdata = new TextItemData();
                    _tempItemdata._ObjName = _tempAllText[j].gameObject.name;
                    _tempItemdata._TextContext = _tempAllText[j].text
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值