html网站地图在线生成,个人备案能建立企业网站吗,上海闵行医院,免费网站域名注册申请我是编程一个菜鸟#xff0c;英语又不好#xff0c;有的插件非常牛#xff01;我想学一学#xff0c;页面全是英文#xff0c;完全不知所措#xff0c;我该怎么办啊...尝试在Unity中汉化一个插件
效果#xff1a; 思路#xff1a;
如何在Unity中把一个自己喜欢的插件…我是编程一个菜鸟英语又不好有的插件非常牛我想学一学页面全是英文完全不知所措我该怎么办啊...尝试在Unity中汉化一个插件
效果 思路
如何在Unity中把一个自己喜欢的插件变成中文在Unity中编写插件一般会用到编辑器扩展
在编辑器扩展中想在Inspector显示自己想要的属性名或者别的什么就需要用到编辑器扩展的API
把这些固定的API存到一个字典里例如“EditorGUILayout.PropertyField”“LabelField”...我可以尝试先读取我们想要汉化插件的Editor文件夹下的每一个代码的每一行
把每一行的每个字符与字典做一个对比
对比成功就说明此行代码可以被汉化收集可以被汉化的代码行然后把可以被汉化的代码行替换成我们想要的代码
替换成功后保存代码听起来好像没啥问题试试看创建一个存储字典的代码
using System.Collections.Generic;
using UnityEngine;[CreateAssetMenu()]
public class SearchCharacterData : ScriptableObject
{[Header(检索字符对)]public ListItem items;[Header(添加字符对)]public bool addItem false;private void OnValidate(){if (addItem){addItem false;items.Add(new Item());}}/// summary/// 物品数据/// /summary[System.Serializable]public class Item{public string startStr;public string endStr;}
} 完成之后我们就可以在项目中创建一个自定义字典了 在字典中添加几对常用AIP用来测试 创建一个编辑器窗口代码
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;[System.Serializable]
public class Editor_ChinesizationTool : EditorWindow
{private static Editor_ChinesizationTool _window;[MenuItem(Tools/汉化编辑器)]public static void GUIDRefReplaceWin(){Rect wr new Rect(0, 0, 300, 1000);//窗口大小_window (Editor_ChinesizationTool)GetWindow(typeof(Editor_ChinesizationTool), true, 汉化编辑);// false 表示不能停靠的_window.Show();}
}没想到要去翻译一个插件竟然要自己先写一个...造孽啊~读文件 /// summary/// 读取数据/// /summary/// returns/returnspublic Liststring ReadFileInfo(bool IsUpdateNewData true){Datas.Clear();CurrentDatas.Clear();CurrentSplitDatas.Clear();if (IsUpdateNewData) NewSplitDatas.Clear();StreamReader sr null;//读取string assetsName FileInfo.FullName;sr File.OpenText(assetsName.Substring(assetsName.IndexOf(Assets)));//读取文件//读取所有行int line 0;string data null;do{data sr.ReadLine();if (data ! null){Datas.Add(data);CurrentDatas.Add(data);foreach (var item in searchCharacterData.items){string csData FindString(data, item.startStr, item.endStr);if (csData ! ){CurrentSplitDatas.Add(new NewCSData(line, csData));if (IsUpdateNewData) NewSplitDatas.Add(new NewCSData(line, csData));break;}}}line;} while (data ! null);sr.Close();//关闭流sr.Dispose();//销毁流return CurrentDatas;}将改好的数据进行写入 void WriteFileInfo(Liststring datas){StreamWriter sw;//写入if (!FileInfo.Exists){Debug.LogError(无法写入没有该文件);return;}ClearData(path);sw FileInfo.AppendText();//打开文件foreach (string linedata in datas){sw.WriteLine(linedata);}sw.Flush();//清除缓冲区sw.Close();//关闭流sw.Dispose();//销毁流//ReadFileInfo();}稍稍修正一下编辑器页面随便导入一个插件试试看
源码
注意此文件需要放在Editor文件夹下才可以正常使用using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;[System.Serializable]
public class Editor_ChinesizationTool : EditorWindow
{private static Editor_ChinesizationTool _window;public string modelPath Assets;public ListCSData cslist new ListCSData();public static Rect modelRect;int maxLineCount 5;Vector2 csDataPos, contentPos;SearchCharacterData searchCharacterData null;CSData CurrentCSData null;[MenuItem(Tools/汉化编辑器)]public static void GUIDRefReplaceWin(){Rect wr new Rect(0, 0, 300, 1000);//窗口大小_window (Editor_ChinesizationTool)GetWindow(typeof(Editor_ChinesizationTool), true, 汉化编辑);// false 表示不能停靠的_window.Show();}private Material m_material;//1private void OnEnable(){m_material new Material(Shader.Find(Hidden/Internal-Colored));//2m_material.hideFlags HideFlags.HideAndDontSave;//3}void OnGUI(){EditorGUILayout.Space();EditorGUILayout.LabelField(将文件夹拖拽到此处);EditorGUILayout.Space();GUI.SetNextControlName(input1);//设置下一个控件的名字modelRect EditorGUILayout.GetControlRect();modelPath EditorGUI.TextField(modelRect, modelPath);EditorGUILayout.Space();DragFolder();EditorGUILayout.Space();searchCharacterData EditorGUILayout.ObjectField(, searchCharacterData, typeof(SearchCharacterData), true) as SearchCharacterData;// 导出材质if (searchCharacterData null){GUILayout.Label(请添加字典);return;}if (GUILayout.Button(读取文件)){ReadFile();CurrentCSData null;}if (CurrentCSData null){int currentLineCount 1;csDataPos EditorGUILayout.BeginScrollView(csDataPos, GUILayout.Width(1000), GUILayout.Height(500));bool isLineEnd true;maxLineCount EditorGUILayout.IntField(每行显示脚本的个数, maxLineCount);foreach (CSData csdate in cslist){if (currentLineCount 1){GUILayout.BeginHorizontal();isLineEnd false;}if (GUILayout.Button(csdate.name)){CurrentCSData csdate;}if (currentLineCount maxLineCount){GUILayout.EndHorizontal();currentLineCount 0;isLineEnd true;}currentLineCount;}if (isLineEnd false){GUILayout.EndHorizontal();}GUILayout.EndScrollView();}if (CurrentCSData ! null){EditorGUILayout.BeginVertical(HelpBox);GUILayout.BeginHorizontal();csDataPos EditorGUILayout.BeginScrollView(csDataPos, GUILayout.Width(500), GUILayout.Height(700));#region 显示代码int line 1;lineLocations.Clear();foreach (var date in CurrentCSData.CurrentDatas){GUILayout.Label(line date);foreach (var item in CurrentCSData.CurrentSplitDatas){if (line item.line){LineLocation lineLocation new LineLocation();Rect rect GUILayoutUtility.GetLastRect();lineLocation.FirstRect new Vector2(rect.x, rect.y - csDataPos.y);lineLocation.FirstRectOffset csDataPos;lineLocations.Add(lineLocation);}}line;}GUILayout.EndScrollView();GUILayout.Space(100);#endregioncontentPos EditorGUILayout.BeginScrollView(contentPos, GUILayout.Width(700), GUILayout.Height(700));for (int i 0; i CurrentCSData.CurrentSplitDatas.Count; i){//GUILayout.BeginHorizontal();GUILayout.Label(CurrentCSData.CurrentSplitDatas[i].line 1 CurrentCSData.CurrentDatas[CurrentCSData.CurrentSplitDatas[i].line]);//找到可更换数据lineLocations[i].FirstRect.y contentPos.y;lineLocations[i].LastRectOffset contentPos;Rect rect GUILayoutUtility.GetLastRect();lineLocations[i].LastRect new Vector2(rect.x, rect.y);CurrentCSData.NewSplitDatas[i].data EditorGUILayout.TextField(CurrentCSData.NewSplitDatas[i].data);//GUILayout.EndHorizontal();}foreach (var item in lineLocations){m_material.SetPass(0);//4GL.Begin(GL.LINES);GL.Color(Color.red);GL.Vertex3(item.FirstRect.x - 10010, LimitMax(item.FirstRect.y 30,690 item.LastRectOffset.y, item.LastRectOffset.y), 0);GL.Vertex3(item.FirstRect.x - 10510, LimitMax(item.FirstRect.y 30, 690 item.LastRectOffset.y, item.LastRectOffset.y), 0);GL.End();GL.Begin(GL.LINES);GL.Color(Color.black);GL.Vertex3(item.FirstRect.x - 10010, LimitMax(item.FirstRect.y 30,690 item.LastRectOffset.y, item.LastRectOffset.y), 0);//GL.Vertex3(item.LastRect.x-10, LimitMax(item.LastRect.y 10, 690 item.LastRectOffset.y, item.LastRectOffset.y), 0); GL.End();GL.Begin(GL.LINES);GL.Color(Color.red);GL.Vertex3(item.LastRect.x-10, LimitMax(item.LastRect.y 10, 690 item.LastRectOffset.y, item.LastRectOffset.y), 0);GL.Vertex3(item.LastRect.x-5, LimitMax(item.LastRect.y 10, 690 item.LastRectOffset.y, item.LastRectOffset.y), 0);GL.End();//Debug.Log(FirstRect: item.FirstRect__ LastRect: item.LastRect);//break;}GUILayout.EndScrollView();GUILayout.EndHorizontal();GUILayout.BeginHorizontal();if (GUILayout.Button(确认更改)){CurrentCSData.ReadFileInfo(false);for (int i 0; i CurrentCSData.CurrentSplitDatas.Count; i){CurrentCSData.CurrentDatas[CurrentCSData.CurrentSplitDatas[i].line] ReplaceStr(CurrentCSData.CurrentDatas[CurrentCSData.CurrentSplitDatas[i].line],CurrentCSData.CurrentSplitDatas[i].data,CurrentCSData.NewSplitDatas[i].data);}for (int i 0; i CurrentCSData.Datas.Count; i){CurrentCSData.Datas[i] CurrentCSData.CurrentDatas[i];}CurrentCSData.WriterData();AssetDatabase.Refresh();}if (GUILayout.Button(重新选择文件)){CurrentCSData null;}GUILayout.EndHorizontal();GUILayout.EndVertical();}EditorGUILayout.Space();}ListLineLocation lineLocations new ListLineLocation();public class LineLocation{public Vector2 FirstRectOffset;public Vector2 FirstRect;public Vector2 LastRectOffset;public Vector2 LastRect;}public void ReadFile(){GetAllFilesAndDertorys(modelPath, searchCharacterData);}/// summary/// 获得拖拽文件/// /summaryvoid DragFolder(){//鼠标位于当前窗口if (mouseOverWindow this){//拖入窗口未松开鼠标if (Event.current.type EventType.DragUpdated){DragAndDrop.visualMode DragAndDropVisualMode.Generic;//改变鼠标外观// 判断区域if (modelRect.Contains(Event.current.mousePosition))GUI.FocusControl(input1);}//拖入窗口并松开鼠标else if (Event.current.type EventType.DragExited){string dragPath string.Join(, DragAndDrop.paths);// 判断区域if (modelRect.Contains(Event.current.mousePosition))modelPath dragPath;// 取消焦点(不然GUI不会刷新)GUI.FocusControl(null);}}}static string FindString(string str, string StartStr, string EndStr){if (str.Length 3)return ;int index3 str.IndexOf(StartStr);if (index3 ! -1){int index4 str.IndexOf(EndStr, index3);if (index4 ! -1){return str.Substring(index3 StartStr.Length, index4 - index3 - StartStr.Length);}}return ;}void GetAllFilesAndDertorys(string _path, SearchCharacterData searchCharacterData){//判断路径是否存在if (Directory.Exists(_path)){#region 找到Editor文件夹DirectoryInfo dir new DirectoryInfo(_path);DirectoryInfo[] allDirs dir.GetDirectories(*, SearchOption.AllDirectories);string EditorPath ;foreach (var item in allDirs){//忽略.metaif (item.Name.EndsWith(.meta)) continue;string assetsName item.FullName;assetsName assetsName.Substring(assetsName.IndexOf(Assets));if (item.Name Editor){EditorPath assetsName;break;}}#endregionif (EditorPath ! ){#region 得到Editor文件夹下所有的.cs文件DirectoryInfo editorDir new DirectoryInfo(EditorPath);cslist.Clear();int ListIndex 0;foreach (var item in editorDir.GetFiles(*, SearchOption.AllDirectories)){//忽略.metastring assetsName item.FullName;assetsName assetsName.Substring(assetsName.IndexOf(Assets));if (item.Name.EndsWith(.meta)) continue;if (item.Name.EndsWith(.cs)){cslist.Add(new CSData(ListIndex, item, assetsName, searchCharacterData, this));}ListIndex;}#endregionforeach (var item in cslist){item.ReadFileInfo();}}else{Debug.LogError(该目录没有Editor文件夹);}}}string ReplaceStr(string str, string oldStr, string newStr){if (str.Length 3)return ;int strIndex str.IndexOf(oldStr);if (strIndex ! -1){string startStr str.Substring(0, strIndex);string endStr str.Substring(strIndex oldStr.Length);return startStr newStr endStr;}return ;}public float LimitMax(float f, float maxValue 690, float minValue 0){//return f;return Math.Min(maxValue, Math.Max(f, minValue));}[System.Serializable]public class CSData{Editor_ChinesizationTool editor_ChinesizationTool null;SearchCharacterData searchCharacterData null;public string name;private FileInfo fileInfo;public int ListIndex -1;public string path;/// summary/// 原始数据/// /summarypublic Liststring Datas new Liststring();/// summary/// 当前数据/// /summarypublic Liststring CurrentDatas new Liststring();/// summary/// 新数据/// /summarypublic ListNewCSData CurrentSplitDatas new ListNewCSData();public ListNewCSData NewSplitDatas new ListNewCSData();public FileInfo FileInfo{get{if (fileInfo null){editor_ChinesizationTool.ReadFile();fileInfo editor_ChinesizationTool.cslist[ListIndex].FileInfo;}return fileInfo;}set fileInfo value;}public CSData(int mListIndex, FileInfo mfileInfo, string path, SearchCharacterData searchCharacterData, Editor_ChinesizationTool parent){FileInfo mfileInfo;this.path path;this.name FileInfo.Name;this.searchCharacterData searchCharacterData;this.ListIndex mListIndex;this.editor_ChinesizationTool parent;}/// summary/// 写入数据/// /summarypublic void WriterData(){WriteFileInfo(Datas);}/// summary/// 读取数据/// /summary/// returns/returnspublic Liststring ReadFileInfo(bool IsUpdateNewData true){Datas.Clear();CurrentDatas.Clear();CurrentSplitDatas.Clear();if (IsUpdateNewData) NewSplitDatas.Clear();StreamReader sr null;//读取string assetsName FileInfo.FullName;sr File.OpenText(assetsName.Substring(assetsName.IndexOf(Assets)));//读取文件//读取所有行int line 0;string data null;do{data sr.ReadLine();if (data ! null){Datas.Add(data);CurrentDatas.Add(data);foreach (var item in searchCharacterData.items){string csData FindString(data, item.startStr, item.endStr);if (csData ! ){CurrentSplitDatas.Add(new NewCSData(line, csData));if (IsUpdateNewData) NewSplitDatas.Add(new NewCSData(line, csData));break;}}}line;} while (data ! null);sr.Close();//关闭流sr.Dispose();//销毁流return CurrentDatas;}void WriteFileInfo(Liststring datas){StreamWriter sw;//写入if (!FileInfo.Exists){Debug.LogError(无法写入没有该文件);return;}ClearData(path);sw FileInfo.AppendText();//打开文件foreach (string linedata in datas){sw.WriteLine(linedata);}sw.Flush();//清除缓冲区sw.Close();//关闭流sw.Dispose();//销毁流//ReadFileInfo();}void ClearData(string path){StreamWriter tmpWrite new StreamWriter(path);tmpWrite.Write();tmpWrite.Close();}}[System.Serializable]public class NewCSData{public int line 0;public string data ;public NewCSData(int line, string data){this.line line;this.data data;}}
}最后的最后
我自己反正没实践过可以先拿这个玩玩看还是挺有意思的~ 觉得有意思可以改巴改巴也可以把建议放在评论区有空我就更新一下~ Demo源码 文章转载自: http://www.morning.trqhd.cn.gov.cn.trqhd.cn http://www.morning.wdhhz.cn.gov.cn.wdhhz.cn http://www.morning.htjwz.cn.gov.cn.htjwz.cn http://www.morning.knqzd.cn.gov.cn.knqzd.cn http://www.morning.rnkq.cn.gov.cn.rnkq.cn http://www.morning.llcgz.cn.gov.cn.llcgz.cn http://www.morning.grbp.cn.gov.cn.grbp.cn http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.zbjfq.cn.gov.cn.zbjfq.cn http://www.morning.zcmpk.cn.gov.cn.zcmpk.cn http://www.morning.sjli222.cn.gov.cn.sjli222.cn http://www.morning.ywpwg.cn.gov.cn.ywpwg.cn http://www.morning.trqzk.cn.gov.cn.trqzk.cn http://www.morning.txrq.cn.gov.cn.txrq.cn http://www.morning.tlfmr.cn.gov.cn.tlfmr.cn http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn http://www.morning.jjzjn.cn.gov.cn.jjzjn.cn http://www.morning.hrpjx.cn.gov.cn.hrpjx.cn http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn http://www.morning.ykklw.cn.gov.cn.ykklw.cn http://www.morning.zxqyd.cn.gov.cn.zxqyd.cn http://www.morning.rfxyk.cn.gov.cn.rfxyk.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.hjlsll.com.gov.cn.hjlsll.com http://www.morning.ampingdu.com.gov.cn.ampingdu.com http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.saletj.com.gov.cn.saletj.com http://www.morning.kfcz.cn.gov.cn.kfcz.cn http://www.morning.ncqzb.cn.gov.cn.ncqzb.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.xsjfk.cn.gov.cn.xsjfk.cn http://www.morning.hwxxh.cn.gov.cn.hwxxh.cn http://www.morning.msgnx.cn.gov.cn.msgnx.cn http://www.morning.swsrb.cn.gov.cn.swsrb.cn http://www.morning.pynzj.cn.gov.cn.pynzj.cn http://www.morning.trqzk.cn.gov.cn.trqzk.cn http://www.morning.yhwxn.cn.gov.cn.yhwxn.cn http://www.morning.kqzrt.cn.gov.cn.kqzrt.cn http://www.morning.xpzgg.cn.gov.cn.xpzgg.cn http://www.morning.dkgtr.cn.gov.cn.dkgtr.cn http://www.morning.krqhw.cn.gov.cn.krqhw.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.sfnr.cn.gov.cn.sfnr.cn http://www.morning.tdmgs.cn.gov.cn.tdmgs.cn http://www.morning.zglrl.cn.gov.cn.zglrl.cn http://www.morning.ryztl.cn.gov.cn.ryztl.cn http://www.morning.nfpkx.cn.gov.cn.nfpkx.cn http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn http://www.morning.plhyc.cn.gov.cn.plhyc.cn http://www.morning.pnfwd.cn.gov.cn.pnfwd.cn http://www.morning.rcjqgy.com.gov.cn.rcjqgy.com http://www.morning.tknqr.cn.gov.cn.tknqr.cn http://www.morning.rfpxq.cn.gov.cn.rfpxq.cn http://www.morning.lzbut.cn.gov.cn.lzbut.cn http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.elsemon.com.gov.cn.elsemon.com http://www.morning.tpmnq.cn.gov.cn.tpmnq.cn http://www.morning.youngbase.cn.gov.cn.youngbase.cn http://www.morning.fbfnk.cn.gov.cn.fbfnk.cn http://www.morning.xrftt.cn.gov.cn.xrftt.cn http://www.morning.tlyms.cn.gov.cn.tlyms.cn http://www.morning.flqbg.cn.gov.cn.flqbg.cn http://www.morning.zcncb.cn.gov.cn.zcncb.cn http://www.morning.skdrp.cn.gov.cn.skdrp.cn http://www.morning.ndxrm.cn.gov.cn.ndxrm.cn http://www.morning.hnk25076he.cn.gov.cn.hnk25076he.cn http://www.morning.ktrdc.cn.gov.cn.ktrdc.cn http://www.morning.rdgb.cn.gov.cn.rdgb.cn http://www.morning.pbygt.cn.gov.cn.pbygt.cn http://www.morning.ylpl.cn.gov.cn.ylpl.cn http://www.morning.qcwck.cn.gov.cn.qcwck.cn http://www.morning.xymkm.cn.gov.cn.xymkm.cn http://www.morning.hpjpy.cn.gov.cn.hpjpy.cn http://www.morning.tddrh.cn.gov.cn.tddrh.cn http://www.morning.xpqyf.cn.gov.cn.xpqyf.cn http://www.morning.kfcz.cn.gov.cn.kfcz.cn http://www.morning.yuminfo.com.gov.cn.yuminfo.com http://www.morning.qgbfx.cn.gov.cn.qgbfx.cn