Unity4 升級到 Unity5 更新小記,unity4unity5
為了某一個Bug,把遊戲工程從Unity4.6 升級到Unity5 測試,中間出現了一些問題,小記。
(1) Plugin的使用變化
在Unity5.0中,對於每一個匯入的DLL、SO、Jar這些看起來像 Plugin 檔案的檔案,都會有一個選項設定其作用平台。從Unity4.6 升級到 Unity5.0 的時候,有一些檔案不能被正確的判斷平台,就會在Platform 選項上設定為 所有 ,就出現了下面的錯誤。
我們只要找到 對應的檔案,然後設定其作用的平台就可以解決這個BUG。
對於DLL,如果這個DLL檔案並不是Plugin檔案,就取消掉 Platform 的任何勾選。
(2) 廢棄了 AddComponent(string) 介面
從Unity4.6 更新到Unity5.0 ,開啟工程後,Unity會自動檢測代碼並且轉碼到新的API。AddComponent(string) 這個API被轉換到下面的樣子。
addedComponent = UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(go, "Assets/PlayMaker/Actions/AddComponent.cs (56,21)", component.Value);
在UnityEditor 環境下能正常運行居然,但是在匯出Xcode工程時報錯:
Assets/PlayMaker/Actions/AddComponent.cs(56,88): error CS0619: `UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(UnityEngine.GameObject, string, string)' is obsolete: `Method is not meant to be used at runtime. Please, replace this call with GameObject.AddComponent<T>()/GameObject.AddComponent(Type).'
意思就是說這個API唄廢棄了,現在只能使用 AddComponent(T) 了。
於是修改,先用System.Type.GetType(string) 擷取Type,然後在AddComponet 。
但是這樣在IL2CPP上可能會有問題,因為IL2CPP是會裁剪代碼的,所以可能出現AOT編譯問題導致運行時出現類型找不到的BUG。
如果出現這種情況,之前的文章有解決方案:
http://blog.csdn.net/huutu/article/details/43986079