2014-04-03 23 views
4

嗨,我需要與統一整合一點點幫助到Eclipse整合統一和Eclipse

我的參考頁是=>here

我有Unity3D專業版和Android插件專業版

  • 像平常一樣設置Unity Android項目並點擊 Build。
  • 輸入你的項目文件夾,進入Temp/StagingArea。
  • 將所有項目文件複製到一個新文件夾中。
  • 將此文件夾作爲Eclipse中的新Android項目導入。
  • 將此項目標記爲 項目的屬性窗口中的庫。 (右鍵點擊項目名稱,進入屬性 - > Android 並標記「Is Library」。)
  • 在Eclipse中創建一個新的Android項目。這將構成您項目的Java部分 。
  • 將Unity Android項目添加爲新項目的庫。 (右鍵點擊項目名稱,進入屬性 - > Android的,選擇 「添加...」,添加項目。)
  • 的classes.jar庫添加到庫引用您的新 項目。 (在性能,進入Java_Build_path->庫,選擇 「添加外部JAR ...」,瀏覽到 UNITY_INSTALLATION \編輯\ DATA \ PlaybackEngines \和roidplayer \ bin和 添加classes.jar)

現在,如果我將這個小項目放入我的設備中,我會得到類似這樣的內容

您可以從此鏈接看到圖片。

https://copy.com/vVaCyQTEUECV

下一個步驟是這樣的:

  • 從庫項目移動資產文件夾複製到新的項目。 (安卓不允許在庫中使用的資產,這 最後一步有每當統一項目重建重複。)

我從庫項目移動資產文件夾和res文件夾到新項目。

後,我從圖書館移動AndroidMnifest.xml和項目

更換這是MainActivity.java

package com.Developer.PackMan; 

import com.unity3d.player.UnityPlayerNativeActivity; 


import android.os.Bundle; 

public class MainActivity extends UnityPlayerNativeActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

} 
} 

我的代碼,這是明顯的。XML

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.Developer.PackMan" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal"> 
    <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" /> 
    <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false"> 
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"> 
     <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> 
     <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" /> 
    </activity> 
    </application> 
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" /> 
    <uses-feature android:glEsVersion="0x00020000" /> 
    <uses-feature android:name="android.hardware.sensor.accelerometer" /> 
</manifest> 

後,我建立它,我得到了與下面的文本

的應用程序)過程com.Developer.Packman)已意外停止,請重試錯誤。

問題是我沒有在LogCat或Console中收到任何錯誤,一切都很清楚。

我真的需要你的幫助。謝謝。

回答

5

對於需要同時顯示Unity3d和常規Android UI的應用程序,我爲我的未來使用編寫了指南。 AFAIR它基於Unity3d 4.3版本。我希望這是不夠細緻:)

基於鏈接: http://forum.unity3d.com/threads/98315-Using-Unity-Android-In-a-Sub-View/page4?p=1477830&viewfull=1#post1477830

https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse

預設置:

爲了開始整合Unity3d和Android您需要的classes.jar文件在'... Unity \ Editor \ Data \ PlaybackEngines \ androidplayer \ bin'中找到。您可以將它放在工作區目錄中。

設置:

  1. 開始與Android項目將包含所有的Android 位。
  2. 準備Unity3d Android項目。將Unity項目 像常規Android項目一樣導入到您的工作區中。
  3. RMB在Unity項目上,單擊「屬性」,然後轉到「Android」並勾選「是 Library?」複選框。
  4. RMB在Android項目中,單擊「屬性」,然後轉到「Android」,然後單擊「添加」將一個庫(Unity項目)添加到Android項目中。
  5. 仍然在「屬性」對話框中,轉至「Java構建路徑」並選擇「庫」選項卡。 在那裏,單擊「添加外部JAR」並導航到classes.jar 文件。
  6. 確保兩個項目都以同一個SDK爲目標。
  7. 將Unity項目中的「assets」文件夾移動到Android項目中。每次重建Unity項目時,必須重複此步驟 。

編碼:

本指南假設你的目標是擁有一個Android活動,這將同時顯示一個統一的模型和標準Android UI。

  1. 將以下行添加到項目清單文件的基礎:''。
  2. 將清單中的以下行添加到應該包含Unity模型的活動中:''。這可以將觸摸事件傳遞給Unity模型和常規Android UI。
  3. 使活動擴展UnityPlayerActivity而不是Activity。
  4. 不要直接在onCreate()中添加'setContentView' - 這會導致不需要的行爲 - 在我的情況下,Unity模型非常小,無法與之交互;相反,在onResume()找到UnityPlayer對象的父視圖,並在其中充氣佈局並添加所有其他UI元素。請注意,查找所述視圖可能需要在單獨的線程中完成。

故障排除:

  • NoClassDefFoundException(或類似)上延伸UnityPlayerActivity類:去你的Android項目的屬性,那麼Java構建路徑 - >訂單和出口,並勾選classes.jar(在我的情況下,如果這有什麼區別的話,它就位列榜首)。按確定,清理項目,再次嘗試運行,並嘗試...
  • 多個dex文件定義Lcom/unity3d/player/nativeloader - 確保Unity項目中的「libs」目錄不包含「unity-classes.jar 「文件。
  • src文件夾中
  • (不知道,但值得一試)的問題 - 刪除src文件夾

這裏的內容是一些示例代碼來說明其持有Unity3d對象Activity

private Button buttonChangeColour; 
private UnityPlayer unityPlayer = null; 

@Override 
public void onResume() { 

    super.onResume(); 

    if (unityPlayer == null) { 

     View rootView = findViewById(android.R.id.content); 
     unityPlayer = findUnityPlayerView(rootView); 

     if (unityPlayer != null) { 

      ViewGroup unityPlayerParentView = (ViewGroup)(unityPlayer.getParent()); 
      View mainHomeView = getLayoutInflater().inflate(R.layout.activity_home, null); 
      LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 
      unityPlayerParentView.addView(mainHomeView, layoutParams); 

      buttonChangeColour = (Button) findViewById(R.id.buttonChangeColour); 
      buttonChangeColour.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 
        // [...] 
       } 
      }); 
     } 
    } 
} 

private UnityPlayer findUnityPlayerView(View view) { 

    if (view instanceof UnityPlayer) { 

     return (UnityPlayer) view; 
    } 
    if (view instanceof ViewGroup) { 

     ViewGroup childrenViews = (ViewGroup) view; 

     for (int i = 0; i < childrenViews.getChildCount(); i++) { 

      UnityPlayer foundView = findUnityPlayerView(childrenViews.getChildAt(i)); 

      if (foundView != null) { 

       return foundView; 
      } 
     } 
    } 

    return null; 
} 
+0

(對於Unity 4.5):您是否嘗試過在Unity的構建設置對話框中使用[export]「Google Android Project」選項?這創建了一個Android項目。我的方法是將生成的項目合併到我的Android項目中,從Unity生成的項目中獲取所有相關文件,但使用我自己的java文件(這將與統一生成項目中的那些文件相似,但與我自己的項目額外的代碼),我的清單等。然後我會用gradle構建。任何理由爲什麼不行? – treesAreEverywhere

1

你正在使用哪個Unity版本?如果4.X我寫了關於eclipse集成的教程here

也可以查看我以前的教程,我解釋瞭如何在不使用eclipse的情況下編寫插件。

+0

我設法自己整合它。不管怎樣,謝謝你。 – Nicholas