轉載自
Unity Eclipse协同工作配置【含傻瓜版】
http://blog.csdn.net/ldghd/article/details/9251865
將unity project打包 並且import至eclipse裡使用
1. 創建一個unity project
2. 將unity project輸出成eclipse project
Unity視窗 -> Files -> Build Settings -> Platform選擇Android
a. 選擇Player Settings -> 右邊視窗選擇Other Settings
-> Bundle Identifier 填入package名稱(e.g. com.test)
Mininum API Level 選擇最小支援API Level(e.g. Level 8)
b. 回到Build Settings視窗 -> 勾選Create Eclipse project -> 按Export按鈕
-> 選擇輸出的目的地資料夾(e.g. 桌面上的Template)
c. 到unity專案的資料夾底下 -> Temp資料夾下 -> 複製StagingArea資料夾到別處
(e.g. 複製為桌面上的StagingArea)
3. import至eclipse
a. 開啟eclipse
b. 點選上方工具列 File -> Import -> 選擇Android下的Existing Android Code Into Workspace
-> Next -> Browse -> 選擇剛剛複製的StagingArea -> Open -> Finish
完成後會出現一個專案UnityPlayerProxyActivity (或者....PlayerProxyActivity 之類的)
如果專案顯示有error 必須要修正(通常是AndroidManifest.xml)
c. 選擇UnityPlayerProxyActivity -> 右鍵選擇Build Path -> Configure Build Path
-> 選擇左方Android選項 -> 勾選 Is Library -> Apply -> OK
此步驟完成後 會在該專案的bin底下生成一個jar檔 (unityplayerproxyactivity.jar)
此jar即可讓其他eclipse android project使用
d. 新建立一個project, File -> New -> Other -> Android Application Project
之後按照需求填寫, 必須注意package name必須要和unity project的Bundle Identifier一樣
(例子中為 com.test) 假設此Project名為UnityGame
e. 點選UnityGame -> 右鍵選擇Build Path -> Configure Build Path -> 選擇左方Android選項
-> 下方Library的部分 選擇Add -> 選擇剛剛的UnityPlayerProxyActivity -> Apply -> OK
f. 刪除UnityPlayerProxyActivity中assets下的所有項目
g. 如果UnityGame中有error 必須修正
h.打開兩個資料夾視窗 一個是UnityGame的專案資料夾 一個是Template
i. 把Template下所有的東西都複製到UnityGame中(按自己需求 通常res我不會複製)
j. 回到eclipse 按F5重新整理
k. 選擇UnityGame -> 右鍵選擇BuildPath -> Configure Build Path -> 上方分頁選擇Library
-> Add Jars -> 選擇classes.jar(如果發現沒有再library裡面才需要做)
-> Add Jars -> 選擇UnityPlayerProxyActivity中bin底下的unityplayerproxyactivity.jar
l. 選擇Order and Export選項 -> 將classes.jar和unityplayerproxyactivity.jar勾起來 -> OK
4. 完成
在加進去後 如果想要讓app一打開就是unity畫面 就不需要做其他修改了
但如果是想要讓自己寫的activity去call unity 那還需要做一些更動
1. 修改AndroidManifest.xml檔案
找到被設定為main activity的activity
(含有
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
該activity名稱應該是com.test.unityProjectProxyActivity
其中com.test是該unity專案的Bundle Identifier
unityProjectProxyActivity則是unity project + ProxyActivity)
將<intent-filter> .... </intent-filter>給刪除 讓其不是main activity
2. 新增一個activity 並設定其為main activity
例如我設定為
<activity android:name="com.test.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3.再專案的src下 新增對應的main activity
並在其中使用Intent和startActivity去呼叫unity遊戲
Intent intent = new Intent(MainActivity.this, com.test.unityProjectProxyActivity.class);
startActivity(intent);
其中com.test.unityProjectProxyActivity就是AndroidManifest.xml當中看到的那個unity activity
此方法目前有個缺點(?) 就是在自己寫的activity去呼叫unity activity
在切換時 會出現unity logo的畫面 這是unity project的特色(?)
應該沒有辦法控制和刪除吧...?
Import unity project into eclipse
最新推荐文章于 2021-05-27 09:16:00 发布