2013-03-07 38 views
0

我已經根據指示here創建了基於Vuforia/Unity項目的Eclipse項目。這是正在運行。在Unity Android/Eclipse項目中檢測啓動屏幕退出

我在我的主要活動中添加一個按鈕,從QCARPlayerActivity擴展。這也適用,但是,隨着Unity啓動畫面播放,該按鈕位於Unity播放器的頂部。

有沒有什麼辦法可以檢測Unity啓動畫面何時退出,因此在場景加載前我沒有控制權?

UPDATE 13年3月18日

我添加了一個靜態布爾我在Eclipse中的主要活動跟蹤閃屏完成,修改,增加了控制觀看布爾的代碼。

MainActivity.java

public static boolean splashComplete = false; 
private View mControlViewContainer = null; // initialized in onCreate 

class QCARViewFinderTask extends TimerTask { 
    public void run() { 
     MainActivity.this.runOnUiThread(new Runnable() { 
      public void run() { 
       if (!QCAR.isInitialized()) return; //wait for QCAR init 
//search for QCAR view if it hasn't been found 
       if (mQCARView == null) 
       { 
        View rootView = MainActivity.this.findViewById(android.R.id.content); 
        QCARUnityPlayer qcarView = findQCARView(rootView); 
        if (qcarView != null) { 
         mQCARParentView = (ViewGroup)(qcarView.getParent()); 
         mQCARView = qcarView; 
        } 
       }      

       // add controls if QCAR view is located and the splash sequence is complete 
       if(mQCARView != null && splashComplete && mControlViewContainer != null){ 
        mQCARParentView.addView(mControlViewContainer); 
        mViewFinderTimer.cancel(); 
        mViewFinderTimer = null; 
       } 
      } 
     }); 
    } 
} 

在Unity我創建了一個簡單的腳本來設置Java中的靜態布爾和它連接到Vuforia ARCamera

SplashExit.js

function Start() { 
    var mainActivity = new AndroidJavaClass ("com.example.app.MainActivity"); 
    mainActivity.SetStatic.("splashComplete",true); 
} 

這在一個場景簡單的項目中工作得很好。我的控件似乎在飛濺退出時加載。然而,當我在更復雜的場景中使用這種方法時,控制器會在啓動畫面消失之前出現一秒鐘左右。

是否有更好的地方可以將我的Unity腳本或更好的方法附加到腳本中,以更準確地反映飛濺序列何時退出?也許傑爾達克在評論中的建議?

+1

的統一標記是微軟統一。請不要濫用它。 – 2013-03-08 06:48:28

+0

明白了。謝謝! – 2013-03-08 13:18:52

+0

我認爲這是基於Unity iOS許可的Unity基礎?除了一個乾淨的方法,你可以創建一個空的水平瓦特/一個腳本調用Application.LoadLevel加載您的實際水平?我不記得Splash是否顯示所有級別的加載或只是啓動應用程序。 – Jerdak 2013-03-08 14:19:02

回答

0

添加yield語句的確有用。完整的解決方案

SplashExit.js應附於在Unity ARCamera遊戲對象。啓動方法將暫停,直到場景加載完畢,然後在MainActivity.java中將splashComplete設置爲true。

如MainActivity.java定時器重複調用QCARViewFinderTask的運行方法,所述控制視圖將被添加到作爲splashComplete轉換爲true統一播放父視圖。

MainActivity.java

public class MainActivity extends QCARPlayerActivity { 
    private QCARUnityPlayer mQCARView = null; 
    private ViewGroup mQCARParentView = null; 
    private Timer mViewFinderTimer = null; 
    private View mControlViewContainer = null; 

    public static boolean splashComplete = false; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     mControlViewContainer = getLayoutInflater().inflate(R.layout.control_layout, null); 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     if (mQCARView == null) { 
      //search the QCAR view 
      mViewFinderTimer = new Timer(); 
      mViewFinderTimer.scheduleAtFixedRate(new QCARViewFinderTask(), 1000, 1000); 
     } 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     if (mViewFinderTimer != null) { 
      mViewFinderTimer.cancel(); 
      mViewFinderTimer = null; 
     } 
    } 

    class QCARViewFinderTask extends TimerTask { 
     public void run() { 
      MainActivity.this.runOnUiThread(new Runnable() { 
       public void run() { 
        if (!QCAR.isInitialized()) return; //wait for QCAR init 

        //search for QCAR view if it hasn't been found 
        if (mQCARView == null) 
        { 
         View rootView = MainActivity.this.findViewById(android.R.id.content); 
         QCARUnityPlayer qcarView = findQCARView(rootView); 
         if (qcarView != null) { 
          mQCARParentView = (ViewGroup)(qcarView.getParent()); 
          mQCARView = qcarView; 
         } 
        }      

        // add controls if QCAR view is located and the splash sequence is complete 
        if(mQCARView != null && splashComplete && mControlViewContainer != null){ 
         mQCARParentView.addView(mControlViewContainer); 
         mViewFinderTimer.cancel(); 
         mViewFinderTimer = null; 
        } 
       } 
      }); 
     } 

     private QCARUnityPlayer findQCARView(View view) { 
      if (view instanceof QCARUnityPlayer) { 
       return (QCARUnityPlayer)view; 
      } 
      if (view instanceof ViewGroup) { 
       ViewGroup vg = (ViewGroup)view; 
       for (int i = 0; i

SplashExit.js

function Start() { 
    yield; // wait for the scene to fully load 
    // Note that com.example.app.MainActivity should be updated to match your bundle identifier and class names 
    var mainActivity = new AndroidJavaClass ("com.example.app.MainActivity"); 
    mainActivity.SetStatic.("splashComplete",true); 
}