检测团结的Andr​​oid / Eclipse项目的启动画面退出 [英] Detect splash screen exit on Unity Android/Eclipse project

查看:164
本文介绍了检测团结的Andr​​oid / Eclipse项目的启动画面退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照说明<创建的基础上Vuforia /统一项目Eclipse项目href=\"https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse\"相对=nofollow>此处。这是启动和运行。

I've created an Eclipse project based on a Vuforia/Unity project by following the instructions here. That's up and running.

我添加一个按钮,我的主要活动,从QCARPlayerActivity延伸。这也适用,但是,该按钮位于上统一播放器作为统一启动画面的戏剧的顶部。

I am adding a button to my main activity, extends from QCARPlayerActivity. That also works, however, the button sits on top of the Unity player as the Unity splash screen plays.

有没有什么办法的时候团结闪屏退出,所以我在现场加载之前不具有控制,以检测?

Is there any way to detect when the Unity splash screen exits so I don't have controls in place before the scene loads?

更新13年3月18日

我添加了一个静态布尔我在Eclipse中的主要活动跟踪闪屏完成,并修改了code,增加了控制观看布尔。

I've added a static boolean to my main activity in Eclipse to track splash screen completion and modified the code that adds the controls to watch the boolean.

MainActivity.java

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;
                }
            }
        });
    }
}

在团结我创建了一个简单的脚本来设置Java中的静态布尔和它连接到Vuforia ARCamera

In Unity I created a simple script to set the static boolean in Java and attached it to the Vuforia ARCamera

SplashExit.js

SplashExit.js

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

这工作得相当好与一个简单的场景的项目。我的控制似乎泼上出口装载。当我用这个方法有一个比较复杂的场景,然而,控制拿出一秒钟左右之前启动画面消失。

This works fairly well in a project with a simple scene. My controls seem to load on splash exit. When I use this method with a more complicated scene, however, the controls come up a second or so before the splash screen disappears.

有一个更好的地方附上我的统一的脚本,或者脚本中更好的方法,当飞溅序列退出,将更加准确地反映?也许Jerdak的在评论中建议吗?

Is there a better place to attach my Unity script, or a better method within the script, that will more accurately reflect when the splash sequence has exited? Perhaps Jerdak's suggestion in the comments?

推荐答案

添加产量声明没有的伎俩。完整的解决方案如下。

Adding a yield statement did the trick. Full solution follows.

SplashExit.js应附在Unity ARCamera游戏对象。 start方法将停止,直到现场已装起来,然后在MainActivity.java设置splashComplete为true。

SplashExit.js should be attached to the ARCamera Game object in Unity. The start method will stall until the scene has loaded up, then set splashComplete to true in MainActivity.java.

作为MainActivity.java定时器重复调用QCARViewFinderTask的run方法,控制视图将被添加到为splashComplete过渡到真正的统一球员父视图。

As the timer in MainActivity.java repeatedly calls the run method of QCARViewFinderTask, the control view will be added to the Unity Player parent view as splashComplete transitions to true.

MainActivity.java

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

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);
}

这篇关于检测团结的Andr​​oid / Eclipse项目的启动画面退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆