public Text[] yourTexts;
public void 更新所有語言翻譯()
{
yourTexts =
/*FindObjectsOfType<Text>()*/
Resources.FindObjectsOfTypeAll<Text>();
......
......
}
這裡有兩種方法可以用
1. FindObjectsOfType<Text>();
2.Resources.FindObjectsOfTypeAll<Text>();
Declaration
public static Object[] FindObjectsOfType(Type type);Declaration
public static Object[] FindObjectsOfType(Type type, bool includeInactive);Declaration
public static T[] FindObjectsOfType(bool includeInactive);Declaration
public static T[] FindObjectsOfType();Parameters
type | The type of object to find. |
includeInactive | If true, components attached to inactive GameObjects are also included. |
用FindObjectsOfType<Text>()有個問題是新的文檔有一個
"includeInactive"的參數,
但我自己在2019.2的版本中是沒有辦法使用這個參數的,
論壇上也有遇到一樣的問題,
也就是說這個方法在舊版本中,
是只能找尋場景中開啟的物件,
Resources.FindObjectsOfTypeAll
Declaration
public static T[] FindObjectsOfTypeAll();Description
Returns a list of all objects of Type T
.
This function can return any type of Unity object that is loaded, including game objects, prefabs, materials, meshes, textures, etc. It will also list internal objects, therefore be careful with the way you handle the returned objects.
Contrary to Object.FindObjectsOfType this function will also list disabled objects.
Resources.FindObjectsOfTypeAll<Text>()可以避免掉這個問題,
但也就會載入所有東西進去,
如果是做翻譯或改全部的字體還是可以使用的,
當然最好還是一開始就把文字的關聯性處理好,
這是比較亡羊補牢的方法,
還要再驗證一下會不會出其他問題。
(っ´ω`c)
Resources.FindObjectsOfTypeAll() 要注意prefabs的問題,
回覆刪除有時候把資源改了,引擎上看不出問題,但實際輸出跑出來的東西是資源被改了,
結果而言把用不到的prefabs解除可以修復。
(つд⊂)