检测Unity Android/Eclipse项目上的启动屏幕退出
我按照说明创建了一个基于Vuforia/Unity项目的Eclipse项目。那就开始运行了 我在我的主要活动中添加了一个按钮,扩展自QCarPlayerPractivity。但是,当Unity启动屏幕播放时,按钮位于Unity播放器的顶部 有没有办法检测Unity启动屏幕何时退出,这样在加载场景之前我就没有控制了 2013年3月18日更新 我在Eclipse中的主要活动中添加了一个静态布尔值来跟踪启动屏幕的完成情况,并修改了添加控件以观察布尔值的代码 MainActivity.java检测Unity Android/Eclipse项目上的启动屏幕退出,android,eclipse,unity3d,splash-screen,Android,Eclipse,Unity3d,Splash Screen,我按照说明创建了一个基于Vuforia/Unity项目的Eclipse项目。那就开始运行了 我在我的主要活动中添加了一个按钮,扩展自QCarPlayerPractivity。但是,当Unity启动屏幕播放时,按钮位于Unity播放器的顶部 有没有办法检测Unity启动屏幕何时退出,这样在加载场景之前我就没有控制了 2013年3月18日更新 我在Eclipse中的主要活动中添加了一个静态布尔值来跟踪启动屏幕的完成情况,并修改了添加控件以观察布尔值的代码 MainActivity.java publ
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;
}
}
});
}
}
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
在Unity中,我创建了一个简单的脚本来设置Java中的静态布尔值,并将其附加到Vuforia ARCamera
SplashExit.js
function Start () {
var mainActivity = new AndroidJavaClass ("com.example.app.MainActivity");
mainActivity.SetStatic.("splashComplete",true);
}
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);
}
这在具有简单场景的项目中非常有效。我的控件似乎加载到飞溅出口。然而,当我在更复杂的场景中使用这种方法时,控件会在闪屏消失前出现一秒钟左右
是否有更好的地方附加我的Unity脚本,或者脚本中有更好的方法,可以更准确地反映启动序列退出时的情况?也许Jerdak在评论中的建议?添加收益率声明起到了作用。完整的解决方案如下 SplashExit.js应该连接到Unity中的ARCamera游戏对象。start方法将暂停,直到场景加载完毕,然后在MainActivity.java中将splashComplete设置为true 当MainActivity.java中的计时器反复调用QCARViewFinderTask的run方法时,控件视图将在转换为true时添加到Unity Player父视图中 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;
}
}
});
}
}
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
public class main活动扩展了QCARPlayerActivity{
私有QCARUnityPlayer mQCARView=null;
私有视图组mQCARParentView=null;
专用计时器mViewFinderTimer=null;
私有视图mControlViewContainer=null;
公共静态布尔值splashComplete=false;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mControlViewContainer=GetLayoutFlater()。充气(R.layout.control\u布局,null);
}
@凌驾
恢复时公开作废(){
super.onResume();
if(mQCARView==null){
//搜索QCAR视图
mViewFinderTimer=新计时器();
mViewFinderTimer.scheduleAtFixedRate(新的QCARViewFinderTask(),10001000);
}
}
@凌驾
公共无效暂停(){
super.onPause();
if(mViewFinderTimer!=null){
mViewFinderTimer.cancel();
mViewFinderTimer=null;
}
}
类QCARViewFinderTask扩展了TimerTask{
公开募捐{
MainActivity.this.runOnUiThread(新的Runnable(){
公开募捐{
if(!QCAR.isInitialized())返回;//等待QCAR init
//如果未找到QCAR视图,则搜索该视图
if(mQCARView==null)
{
View rootView=MainActivity.this.findviewbyd(android.R.id.content);
QCARUnityPlayer qcarView=findQCARView(rootView);
if(qcarView!=null){
mQCARParentView=(ViewGroup)(qcarView.getParent());
mQCARView=qcarView;
}
}
//如果QCAR视图已定位且飞溅序列已完成,则添加控件
if(mQCARView!=null&&splashplete&&mControlViewContainer!=null){
mQCARParentView.addView(mControlViewContainer);
mViewFinderTimer.cancel();
mViewFinderTimer=null;
}
}
});
}
专用QCARUnityPlayer findQCARView(视图){
if(查看QCARUnityPlayer的实例){
返回(QCARUnityPlayer)视图;
}
if(视图组的视图实例){
ViewGroup vg=(ViewGroup)视图;
对于(int i=0;i
SplashExit.js
function Start () {
var mainActivity = new AndroidJavaClass ("com.example.app.MainActivity");
mainActivity.SetStatic.("splashComplete",true);
}
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);
}
函数启动(){
yield;//等待场景完全加载
//请注意,应更新com.example.app.MainActivity以匹配捆绑包标识符和类名
var mainActivity=新的AndroidJavaClass(“com.example.app.mainActivity”);
mainActivity.SetStatic.(“splashComplete”,true);
}
unity标签是针对Microsoft unity的。请不要误用它。我假设这是unity basic,具有unity iOS许可证?除非使用干净的方法,否则您是否可以创建一个空的级别,并使用调用Application.LoadLevel的单个脚本来加载您的实际级别?我记不起是在所有级别加载之间还是在启动应用程序时显示飞溅@Jerdak这是Unity Pro和Unity Android许可证。我可能没有遵循,但我不确定如何使用此方法在启动序列完成时通知我的包装器活动。@JasonGeorge我使用移动许可证已经有一段时间了,但在PC上,启动仅在第一级加载之前显示,因此我对创建虚拟级别。但是如果你只是想找一个触发splashComplete的地方,怎么样。@Jerdak我尝试了onlevelwasload,但似乎没有触发。在设置splashComplete变量之前添加一个屈服值就成功了。它似乎会暂停例程,直到第一帧有机会渲染为止。