1 回答

TA貢獻1839條經驗 獲得超15個贊
UnityEditor.AssetPreview
屬于UnityEditor
命名空間。
這只存在于 Unity 編輯器 istelf 中,并在構建中被刪除。
=> 您不能UnityEditor
在構建中使用命名空間中的任何內容。
基本上有兩種解決方案可以UnityEditor
從構建中排除某些內容:
預處理器
在 C# 中,您可以使用 in#if preprocessor
來根據全局定義排除代碼塊。Unity 提供了這樣的定義。在這種情況下使用例如
#if?UNITY_EDITOR ????//?CODE?USING?UnityEditor ????#endif
Editor
文件夾
如果整個腳本應從構建中排除,您只需將其放置在名為 的文件夾中Editor
。這將使其完全從構建中剝離。
要在構建中使用它,您要么必須使用另一個庫,要么在 Unity 編輯器中運行此腳本一次,并存儲這些引用以便在構建中使用它們,例如使用屬性[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 關注
- 263 瀏覽
添加回答
舉報