1 回答
TA貢獻1839條經(jīng)驗 獲得超15個贊
UnityEditor.AssetPreview屬于UnityEditor命名空間。
這只存在于 Unity 編輯器 istelf 中,并在構(gòu)建中被刪除。
=> 您不能UnityEditor在構(gòu)建中使用命名空間中的任何內(nèi)容。
基本上有兩種解決方案可以UnityEditor從構(gòu)建中排除某些內(nèi)容:
預(yù)處理器
在 C# 中,您可以使用 in#if preprocessor來根據(jù)全局定義排除代碼塊。Unity 提供了這樣的定義。在這種情況下使用例如
#if?UNITY_EDITOR ????//?CODE?USING?UnityEditor ????#endif
Editor文件夾
如果整個腳本應(yīng)從構(gòu)建中排除,您只需將其放置在名為 的文件夾中Editor。這將使其完全從構(gòu)建中剝離。
要在構(gòu)建中使用它,您要么必須使用另一個庫,要么在 Unity 編輯器中運行此腳本一次,并存儲這些引用以便在構(gòu)建中使用它們,例如使用屬性[ContextMenu]:
? void Start()
? ? {
#if UNITY_EDITOR
? ? ? ? LoadPreviewImages();
#endif
? ? ? ? // if nothing more comes here
? ? ? ? // rather remove this method entirely
? ? ? ? ...
? ? }
#if UNITY_EDITOR
? ? // This allows you to call this method?
? ? // from the according components context menu in the Inspector
? ? [ContextMenu("LoadPreviewImages")]
? ? private void LoadPreviewImages()
? ? {
? ? ? ? foreach (var loadText in ItemTablezz)
? ? ? ? {
? ? ? ? ? ? var getImage = UnityEditor.AssetPreview.GetAssetPreview(loadText.texture);
? ? ? ? ? ? print(getImage);
? ? ? ? ? ? loadText.gameObjectTex = getImage;
? ? ? ? }
? ? }
#endif
- 1 回答
- 0 關(guān)注
- 299 瀏覽
添加回答
舉報
