在Unity Android/Eclipse项目中检测启动屏幕退出
问题描述:
我已经根据指示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脚本或更好的方法附加到脚本中,以更准确地反映飞溅序列何时退出?也许杰尔达克在评论中的建议?
答
添加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);
}
的统一标记是微软统一。请不要滥用它。 – 2013-03-08 06:48:28
明白了。谢谢! – 2013-03-08 13:18:52
我认为这是基于Unity iOS许可的Unity基础?除了一个干净的方法,你可以创建一个空的水平瓦特/一个脚本调用Application.LoadLevel加载您的实际水平?我不记得Splash是否显示所有级别的加载或只是启动应用程序。 – Jerdak 2013-03-08 14:19:02