1. 程式人生 > 其它 >unity 打包時報錯unityEditor不存在

unity 打包時報錯unityEditor不存在

unity報錯:namespace name EditorApplication does not exist

出現這個的原因是因為用了using UnityEngine.UI  ,它屬於UnotyEditor這個名稱空間,而此名稱空間只能在編輯器內用,打包用這個就會報錯。執行時庫

說實話這個問題挺麻煩的,因為我如果要一個關閉按鈕的話,需要用到unityEditor的is_playing()這個方法,但是打包時不能用。查了半天,大概找到了一個解決方法,但是還沒試過。

參考:使用了UnityEditor中的API,打包時卻不能打包UnityEditor的問題 - it610.com 

首先,刪掉using UnityEditor庫

然後引入using System.Windows.Forms;

引入此庫,需要在Asset/Plugin資料夾下放入名為System.Windows.Forms.dll的檔案

此檔案可在Unity的安裝目錄中查詢,然後複製到Plugin資料夾下

具體目錄為:…\Editor\Data\Mono\lib\mono\2.0\System.Windows.Forms.dll

 接下來,就可以在指令碼中成功引入using System.Window.Forms庫

 

想法是用winform的視窗dll替代unityEditor不太確定行不行,有空的話可以試試