国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

網(wǎng)頁(yè)設(shè)計(jì)英文青島關(guān)鍵詞優(yōu)化平臺(tái)

網(wǎng)頁(yè)設(shè)計(jì)英文,青島關(guān)鍵詞優(yōu)化平臺(tái),免費(fèi)手機(jī)版網(wǎng)站建設(shè),網(wǎng)站建設(shè)必須要做404具體流程&#xff1a; 找到工程中使用到的所有字體找到工程和場(chǎng)景中包含Text的所有對(duì)象展示要替換的字體名字讓用戶(hù)選擇通過(guò)用戶(hù)選擇的字體&#xff0c;展示響應(yīng)的物體對(duì)象一鍵替換 通過(guò)AssetDatabase.FindAssets找到工程中包含的所有字體&#xff1a; private List<strin…

具體流程:

  1. 找到工程中使用到的所有字體
  2. 找到工程和場(chǎng)景中包含Text的所有對(duì)象
  3. 展示要替換的字體名字讓用戶(hù)選擇
  4. 通過(guò)用戶(hù)選擇的字體,展示響應(yīng)的物體對(duì)象
  5. 一鍵替換

通過(guò)AssetDatabase.FindAssets找到工程中包含的所有字體:

 private List<string> FindAllFonts(){List<string> list = new List<string>();// 獲取所有字體文件string[] fontGUIDs = AssetDatabase.FindAssets("t:Font");foreach (string fontGUID in fontGUIDs){string fontPath = AssetDatabase.GUIDToAssetPath(fontGUID);Font font = AssetDatabase.LoadAssetAtPath<Font>(fontPath);list.Add(font.name);}list.Add("Arial");//默認(rèn)字體添加進(jìn)去return list;}

?通過(guò)AssetDatabase.FindAssets找到工程中的所有預(yù)制體

  private List<GameObject> GetAllPrefabByAssetDatabase(params string[] path){List<GameObject> _prefabList = new List<GameObject>();string[] _guids = AssetDatabase.FindAssets("t:Prefab", path);string _prefabPath = "";GameObject _prefab;foreach (var _guid in _guids){_prefabPath = AssetDatabase.GUIDToAssetPath(_guid);_prefab = AssetDatabase.LoadAssetAtPath(_prefabPath, typeof(GameObject)) as GameObject;_prefabList.Add(_prefab);}
#if UNITY_2020_1_OR_NEWERText[] texts = GameObject.FindObjectsOfType<Text>(true);foreach (var text in texts){_prefabList.Add(text.gameObject);}
#elseScene activeScene = EditorSceneManager.GetActiveScene();GameObject[] allObjectsInScene = activeScene.GetRootGameObjects();foreach (var obj in allObjectsInScene){Text[] texts = obj.GetComponentsInChildren<Text>(true);foreach (var text in texts){_prefabList.Add(text.gameObject);}}
#endifreturn _prefabList;}

過(guò)濾沒(méi)有含Text組件的對(duì)象

 private List<GameObject> FilterNoTextPrefabs(){List<GameObject> templist = new List<GameObject>();Dic_Font_Prefabs.Clear();foreach (var prefab in prefabs){Text[] texts = prefab.GetComponentsInChildren<Text>(true);if (texts.Length != 0){foreach (var text in texts){if (text.font != null){if (!Dic_Font_Prefabs.ContainsKey(text.font.name)){Dic_Font_Prefabs.Add(text.font.name, new List<GameObject>());//根據(jù)Font類(lèi)型,添加一個(gè)Text集合到字典中}if (!Dic_Font_Prefabs[text.font.name].Contains(prefab)){Dic_Font_Prefabs[text.font.name].Add(prefab);}if (!templist.Contains(prefab)){templist.Add(prefab);//包含該Text的預(yù)制體添加到集合中}}}}}return templist;}

最后,用戶(hù)選擇完要替換的字體,選擇開(kāi)始替換即可。

TextMeshPro跟Text是一個(gè)道理,只需要把代碼中響應(yīng)的Text和Font改為T(mén)extMeshProGUI和FontAssets即可。

最后附上完整代碼:

using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine.UI;
using System.Linq;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
/// <summary>
/// 查找替換工程場(chǎng)景中Text的Font
/// </summary>
public class ChangePrefabFont : EditorWindow
{[MenuItem("Tools/替換字體/Text")]//入口static void GetWindow()//靜態(tài)函數(shù){//創(chuàng)建窗口ChangePrefabFont window = EditorWindow.GetWindow<ChangePrefabFont>("Text字體替換窗口");//生成一個(gè)unity窗口彈窗window.Show();//展示OnGUI中的界面顯示}#region 屬性/// <summary>/// 工程中包含的字體的名字/// </summary>List<string> fontsOnAssets = new List<string>();/// <summary>/// 對(duì)應(yīng)字體是否需要替換/// </summary>List<bool> textPaidFontRelpace = new List<bool>();/// <summary>/// 代替要替換的字體的字體/// </summary>List<Font> textReplaceFonts = new List<Font>();/// <summary>/// 預(yù)制體集合/// </summary>List<GameObject> prefabs = new List<GameObject>();/// <summary>/// 根據(jù)字體類(lèi)型分類(lèi)的預(yù)制體對(duì)象/// </summary>Dictionary<string, List<GameObject>> Dic_Font_Prefabs = new Dictionary<string, List<GameObject>>();#endregionprivate void OnEnable(){InitFont();}private void OnGUI(){InitPrefabs();#region 顯示替換選項(xiàng)EditorGUILayout.LabelField("下面是工程中包含的字體,和工程中&場(chǎng)景中的對(duì)象使用的字體情況。請(qǐng)選擇要替換的字體:");for (int i = 0; i < fontsOnAssets.Count; i++){EditorGUILayout.BeginHorizontal();EditorGUILayout.LabelField($"更換[{fontsOnAssets[i]}]字體");textPaidFontRelpace[i] = EditorGUILayout.Toggle(textPaidFontRelpace[i], GUILayout.Width(position.width));//是否要替換當(dāng)前字體的復(fù)選框EditorGUILayout.EndHorizontal();EditorGUILayout.BeginHorizontal();EditorGUILayout.LabelField($"    預(yù)制體數(shù)量:{GetGetUseFontPrefabCount(fontsOnAssets[i])}");if (!textPaidFontRelpace[i]){if (Dic_Font_Prefabs.ContainsKey(fontsOnAssets[i])){foreach (var item in Dic_Font_Prefabs[fontsOnAssets[i]]){if (prefabs.Contains(item)){prefabs.Remove(item);}}}}else{EditorGUILayout.LabelField($"代替【{fontsOnAssets[i]}】的字體:");textReplaceFonts[i] = (Font)EditorGUILayout.ObjectField(textReplaceFonts[i], typeof(Font), true);//代替的字體復(fù)選框if (Dic_Font_Prefabs.ContainsKey(fontsOnAssets[i])){foreach (var item in Dic_Font_Prefabs[fontsOnAssets[i]]){if (!prefabs.Contains(item)){prefabs.Add(item);}}}}EditorGUILayout.EndHorizontal();}EditorGUILayout.Space();#endregion#region 開(kāi)始替換操作if (GUILayout.Button("開(kāi)始替換")){if (textReplaceFonts == null || textReplaceFonts.Count == 0){EditorUtility.DisplayDialog("提示", "沒(méi)有字體!", "確定");return;}if (prefabs == null || prefabs.Count == 0){EditorUtility.DisplayDialog("提示", "沒(méi)有需要替換的對(duì)象!", "確定");return;}List<GameObject> ReplaceGo = new List<GameObject>();Dictionary<string, Font> Dic_Font_ReplaceFont = new Dictionary<string, Font>();for (int i = 0; i < textPaidFontRelpace.Count; i++){if (textPaidFontRelpace[i] == true){if (textReplaceFonts[i] != null){if (Dic_Font_Prefabs.ContainsKey(fontsOnAssets[i])){ReplaceGo.AddRange(Dic_Font_Prefabs[fontsOnAssets[i]]);Dic_Font_ReplaceFont.Add(fontsOnAssets[i], textReplaceFonts[i]);}else{EditorUtility.DisplayDialog("提示", $"使用了【{fontsOnAssets[i]}】字體的預(yù)制體數(shù)量為0!", "確定");}}else{EditorUtility.DisplayDialog("提示", $"【{fontsOnAssets[i]}】的替代字體為空!", "確定");}}}if (ReplaceGo.Count == 0){EditorUtility.DisplayDialog("提示", "沒(méi)有需要替換的對(duì)象!", "確定");}else{string hintInfo = "";foreach (var font in Dic_Font_ReplaceFont){hintInfo += $"{font.Key} >> {font.Value.name}\n";}if (EditorUtility.DisplayDialog("確認(rèn)進(jìn)行下面的替換?", hintInfo, "確定", "取消")){foreach (var font in Dic_Font_ReplaceFont){ReplaceFont(Dic_Font_Prefabs[font.Key], font.Key, font.Value);}SaveChangedToAsset(prefabs);}}}#endregion#region 預(yù)制體列表InitReorderableList();if (reorderableList != null && reorderableList.count != 0){scrollPos = EditorGUILayout.BeginScrollView(scrollPos);reorderableList.DoLayoutList();EditorGUILayout.EndScrollView();}else{EditorGUILayout.LabelField("提示:沒(méi)有需要替換字體的預(yù)制體");}#endregion}#region 列表和滾動(dòng)窗口ReorderableList reorderableList;//列表顯示Vector2 scrollPos;//滾動(dòng)窗口需要private void DrawHeader(Rect rect){EditorGUI.LabelField(rect, "對(duì)象列表數(shù)量:" + prefabs.Count);}private void DrawElement(Rect rect, int index, bool isActive, bool isFocused){rect.height -= 4;rect.y += 2;prefabs[index] = (GameObject)EditorGUI.ObjectField(rect, "包含Text的對(duì)象", prefabs[index], typeof(GameObject), true);}private void AddItem(ReorderableList list){prefabs.Add(null);}#endregion#region 邏輯方法/// <summary>/// 字體相關(guān)初始化/// </summary>private void InitFont(){textPaidFontRelpace.Clear();textReplaceFonts.Clear();fontsOnAssets = FindAllFonts();foreach (var item in fontsOnAssets){textPaidFontRelpace.Add(false);textReplaceFonts.Add(null);}}/// <summary>/// 預(yù)制體相關(guān)初始化/// </summary>private void InitPrefabs(){prefabs = GetAllPrefabByAssetDatabase();prefabs = FilterNoTextPrefabs();prefabs.Clear();foreach (var item in Dic_Font_Prefabs){prefabs.AddRange(item.Value);}}/// <summary>/// 初始化鏈表操作對(duì)象/// </summary>private void InitReorderableList(){prefabs = prefabs.Distinct().ToList();reorderableList = new ReorderableList(prefabs, typeof(GameObject), true, true, true, true);reorderableList.drawHeaderCallback = DrawHeader;reorderableList.drawElementCallback = DrawElement;reorderableList.onAddCallback = AddItem;}#endregion#region 功能方法#region 查找和過(guò)濾/// <summary>/// 找到工程和場(chǎng)景中的含有Text組件的對(duì)象/// </summary>/// <param name="path"></param>/// <returns></returns>private List<GameObject> GetAllPrefabByAssetDatabase(params string[] path){List<GameObject> _prefabList = new List<GameObject>();string[] _guids = AssetDatabase.FindAssets("t:Prefab", path);string _prefabPath = "";GameObject _prefab;foreach (var _guid in _guids){_prefabPath = AssetDatabase.GUIDToAssetPath(_guid);_prefab = AssetDatabase.LoadAssetAtPath(_prefabPath, typeof(GameObject)) as GameObject;_prefabList.Add(_prefab);}
#if UNITY_2020_1_OR_NEWERText[] texts = GameObject.FindObjectsOfType<Text>(true);foreach (var text in texts){_prefabList.Add(text.gameObject);}
#elseScene activeScene = EditorSceneManager.GetActiveScene();GameObject[] allObjectsInScene = activeScene.GetRootGameObjects();foreach (var obj in allObjectsInScene){Text[] texts = obj.GetComponentsInChildren<Text>(true);foreach (var text in texts){_prefabList.Add(text.gameObject);}}
#endifreturn _prefabList;}/// <summary>/// 過(guò)濾沒(méi)有包含Text的預(yù)制體/// 過(guò)濾沒(méi)有包含付費(fèi)字體的預(yù)制體/// 根據(jù)Text類(lèi)型分類(lèi)/// </summary>/// <param name="gameObjects"></param>/// <returns></returns>private List<GameObject> FilterNoTextPrefabs(){List<GameObject> templist = new List<GameObject>();Dic_Font_Prefabs.Clear();foreach (var prefab in prefabs){Text[] texts = prefab.GetComponentsInChildren<Text>(true);if (texts.Length != 0){foreach (var text in texts){if (text.font != null){if (!Dic_Font_Prefabs.ContainsKey(text.font.name)){Dic_Font_Prefabs.Add(text.font.name, new List<GameObject>());//根據(jù)Font類(lèi)型,添加一個(gè)Text集合到字典中}if (!Dic_Font_Prefabs[text.font.name].Contains(prefab)){Dic_Font_Prefabs[text.font.name].Add(prefab);}if (!templist.Contains(prefab)){templist.Add(prefab);//包含該Text的預(yù)制體添加到集合中}}}}}return templist;}/// <summary>/// 找到工程中的所有字體文件/// </summary>/// <returns>返回字體名稱(chēng)列表</returns>private List<string> FindAllFonts(){List<string> list = new List<string>();// 獲取所有字體文件string[] fontGUIDs = AssetDatabase.FindAssets("t:Font");foreach (string fontGUID in fontGUIDs){string fontPath = AssetDatabase.GUIDToAssetPath(fontGUID);Font font = AssetDatabase.LoadAssetAtPath<Font>(fontPath);list.Add(font.name);}list.Add("Arial");//默認(rèn)字體添加進(jìn)去return list;}#endregion#region 替換字體方法/// <summary>/// 替換Text的字體/// </summary>/// <param name="texts">要替換的Text集合</param>/// <param name="fontName">要替換的字體的名字</param>/// <param name="font">用來(lái)替換的字體</param>private void ReplaceFont(List<GameObject> gameObjects, string fontName, Font font){foreach (var go in gameObjects){Text[] texts = go.GetComponentsInChildren<Text>(true);foreach (var text in texts){if (text.font != null){if (text.font.name == fontName){text.font = font;}}//else//{//    text.font = Resources.GetBuiltinResource<Font>("Arial.ttf");//}}}}/// <summary>/// 保存更改/// </summary>/// <param name="gameObjects"></param>private void SaveChangedToAsset(List<GameObject> gameObjects){foreach (var gameObject in gameObjects){EditorUtility.SetDirty(gameObject);}AssetDatabase.SaveAssets();AssetDatabase.Refresh();EditorUtility.DisplayDialog("提示", "替換完畢!", "確定");}#endregionprivate List<GameObject> GetUseFontPrefabs(string font){if (Dic_Font_Prefabs.ContainsKey(font))return Dic_Font_Prefabs[font];elsereturn null;}private int GetGetUseFontPrefabCount(string font){List<GameObject> temp = GetUseFontPrefabs(font);return temp == null ? 0 : temp.Count;}#endregion
}

http://aloenet.com.cn/news/31158.html

相關(guān)文章:

  • 拓普網(wǎng)站建設(shè)seo點(diǎn)擊優(yōu)化
  • 如果你會(huì)建網(wǎng)站外貿(mào)新手怎樣用谷歌找客戶(hù)
  • 網(wǎng)站推廣適合哪種公司做明星百度指數(shù)排名
  • 網(wǎng)站標(biāo)題堆砌關(guān)鍵詞國(guó)際足聯(lián)世界排名
  • 免費(fèi)建立個(gè)人網(wǎng)站促銷(xiāo)策略的四種方式
  • 企業(yè)管理咨詢(xún)公司招聘成都自動(dòng)seo
  • 廈門(mén)網(wǎng)站建設(shè)多少錢(qián)軟文編輯器
  • 廈門(mén)服裝企業(yè)網(wǎng)站推廣最新小組排名
  • 做網(wǎng)站重要標(biāo)簽成都seo優(yōu)化排名推廣
  • .net網(wǎng)站開(kāi)發(fā)文檔教育培訓(xùn)網(wǎng)站模板
  • 國(guó)家高新技術(shù)企業(yè)證書(shū)圖片北京seo分析
  • 程序員做博彩類(lèi)的網(wǎng)站犯法嗎青島網(wǎng)站建設(shè)運(yùn)營(yíng)推廣
  • 河北高端網(wǎng)站定制公司seo營(yíng)銷(xiāo)優(yōu)化軟件
  • 戴爾網(wǎng)站建設(shè)成功的關(guān)鍵網(wǎng)站怎么做收錄
  • wordpress數(shù)據(jù)庫(kù)導(dǎo)出網(wǎng)址鏈接關(guān)鍵詞推廣優(yōu)化外包
  • 浙江溫州最新消息鄭州seo外包公司哪家好
  • 怎樣開(kāi)發(fā)公司的網(wǎng)站建設(shè)寧波seo怎么推廣
  • 清潔公司百度關(guān)鍵詞在線(xiàn)優(yōu)化
  • 動(dòng)態(tài)網(wǎng)站開(kāi)發(fā)工程師—aspseo一鍵優(yōu)化
  • 網(wǎng)站建設(shè)的需求怎么寫(xiě)項(xiàng)目?jī)?yōu)化seo
  • 寧波網(wǎng)站建設(shè)c nb網(wǎng)站優(yōu)化網(wǎng)
  • 全面做好政府網(wǎng)站建設(shè)管理工作的通知免費(fèi)營(yíng)銷(xiāo)培訓(xùn)
  • 標(biāo)識(shí)設(shè)計(jì)廠(chǎng)家珠海百度搜索排名優(yōu)化
  • 網(wǎng)站制作詳細(xì)流程凈水器十大品牌
  • 網(wǎng)站做視頻在線(xiàn)觀(guān)看網(wǎng)址網(wǎng)站開(kāi)發(fā)合同
  • 陽(yáng)江招聘網(wǎng)站哪個(gè)靠譜松原頭條新聞今日新聞最新
  • 廊坊網(wǎng)站建設(shè)技術(shù)外包百度平臺(tái)聯(lián)系方式
  • 網(wǎng)站頁(yè)腳信息網(wǎng)站播放視頻速度優(yōu)化
  • 電子商務(wù)網(wǎng)站建設(shè)預(yù)算微信公眾平臺(tái)開(kāi)發(fā)
  • 公司網(wǎng)站購(gòu)物平臺(tái)建設(shè)百度網(wǎng)盤(pán)網(wǎng)頁(yè)登錄入口