unity检查预设上的中文
Posted 那个妹子留步
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity检查预设上的中文相关的知识,希望对你有一定的参考价值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Text.RegularExpressions;
using TMPro;
using System.IO;
using System;
public class UiPrefabs
[MenuItem("Tools/检查预设中文并且生成路径")]
static void CheckChinesePrefabsAndSerialization()
string[] prefabPaths = GetAllPrefabs("Assets/Prefab");
if (prefabPaths == null)
return;
List<string> text = new List<string>();
for (int i = 0; i < prefabPaths.Length; i++)
string prefabPath = prefabPaths[i];
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if (prefab == null)
continue;
TextMeshProUGUI[] uiLabels = prefab.GetComponentsInChildren<TextMeshProUGUI>(true);
for (int j = 0; j < uiLabels.Length; j++)
TextMeshProUGUI uiLabel = uiLabels[j];
if (IsIncludeChinese(uiLabel.text))
Debug.LogError(string.Format("路径:0 预设名:1 对象名:2 中文:3", prefabPath, prefab.name, uiLabel.name, uiLabel.text));
text.Add(uiLabel.text);
//进度条
float progressBar = (float)i / prefabPaths.Length;
EditorUtility.DisplayProgressBar("检查预设中文", "进度 :" + ((int)(progressBar * 100)).ToString() + "%", progressBar);
EditorUtility.ClearProgressBar();
AssetDatabase.Refresh();
Debug.Log("完成检查预设中文并且生成路径");
//string path = "Assets/UI/Prefab";
static string[] GetAllPrefabs(string directory)
if (string.IsNullOrEmpty(directory) || !directory.StartsWith("Assets"))
throw new ArgumentException("folderPath");
string[] subFolders = Directory.GetDirectories(directory);
string[] guids = null;
string[] assetPaths = null;
int i = 0, iMax = 0;
foreach (var folder in subFolders)
guids = AssetDatabase.FindAssets("t:Prefab", new string[] folder );
assetPaths = new string[guids.Length];
for (i = 0, iMax = assetPaths.Length; i < iMax; ++i)
assetPaths[i] = AssetDatabase.GUIDToAssetPath(guids[i]);
return assetPaths;
public static bool IsIncludeChinese(string content)
string regexstr = @"[\\u4e00-\\u9fa5]";
if (Regex.IsMatch(content, regexstr))
return true;
else
return false;
以上是关于unity检查预设上的中文的主要内容,如果未能解决你的问题,请参考以下文章
Unity Editor 检查工程Prefab(预设)中的空组件
Unity扩展编辑器学习笔记--从路径下找到拥有某个组件类型的预设
我的 Prefab 上的 Canvas Environment 在 Unity 检查器中显示为灰色,我做了啥?