温州手机网站建设wmwl,苏州最新情况最新消息今天,微信公众号?,北京王府井大楼有些单机项目开发的时候没有做本地文本配置文件#xff0c;全部写死在场景的对象上面#xff0c;简单记录一下怎么提取场景里面的文本并且写入到配置文件里面using System.Collections.Generic;using System.IO;using TMPro;using UnityEditor;using UnityEngine;using Unity…有些单机项目开发的时候没有做本地文本配置文件全部写死在场景的对象上面简单记录一下怎么提取场景里面的文本并且写入到配置文件里面using System.Collections.Generic;using System.IO;using TMPro;using UnityEditor;using UnityEngine;using UnityEngine.UI;public class Test : MonoBehaviour{ static Liststring txtArray new Liststring(); static string labelStr _config_Label_; [MenuItem(Tools/ÌáÈ¡Îı¾)] static void GetAllSceneObjectsWithInactive() { ReadFile(); var allGos Resources.FindObjectsOfTypeAll(typeof(GameObject)); var previousSelection Selection.objects; Selection.objects allGos; var selectedTransforms Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab); Selection.objects previousSelection; int index 0; foreach (var trans in selectedTransforms) { Text text trans.GetComponentText(); string textContent ; if (text null) { TextMeshProUGUI textMeshPro trans.GetComponentTextMeshProUGUI(); if (textMeshPro ! null) { textContent textMeshPro.text; } } else { textContent text.text; } if (!string.IsNullOrEmpty(textContent)!trans.name.Contains(LiberationSans SDF Atlas)) { UILanguageText uILanguageText trans.gameObject.AddComponentUILanguageText(); index index 1; string content ; if (textContent.Contains(\n)) { string[] temp textContent.Split(\n); for (int i 0; i temp.Length; i) { if (i temp.Length -1) { content content temp[i] \\n; } else { content content temp[i]; } } } else { content textContent; } string languageKey string.Format({0}{1}{2}, trans.name, labelStr, index); uILanguageText.languageKey languageKey; txtArray.Add(string.Format({0},{1}, languageKey, content)); Debug.Log(trans.name::: textContent); } } WriteFile(); Debug.Log(ÌáÈ¡½áÊø); } static void WriteFile() { File.WriteAllLines(Application.dataPath /Resources/Language/CN.txt, txtArray); } static void ReadFile() { txtArray.Clear(); string[] strs File.ReadAllLines(Application.dataPath /Resources/Language/CN.txt); for (int i 0; i strs.Length; i) { txtArray.Add(strs[i]); } }}