ARFoundation入门教程U3-android进入unity黑屏及加载优化

从《ARFoundation从零开始3-arfoundation项目》创建项目

一、android端

1. unityLibrary的MainActivity增加两个方法,设置闪屏和关闭闪屏,制作一个闪屏图:
public void SetSplash( )

{

    bgView = new ImageView(mUnityPlayer.currentActivity);

    bgView.setBackgroundResource(R.mipmap.bg);

    bgView.setScaleType(ImageView.ScaleType.FIT_XY);

    mUnityPlayer.addView(bgView);

}



public void HideSplash()

{

    new Handler(Looper.getMainLooper()).post(new Runnable() {

        @Override

        public void run() {

            if(bgView != null)

            {

                try {

                    Thread.sleep(10);

                } catch (InterruptedException e) {

                    e.printStackTrace();

                }

                mUnityPlayer.removeView(bgView);

                bgView = null;

            }

        }

    });

}

 2.在OnCreate中加入SetSplash方法:

protected void onCreate(Bundle savedInstanceState) {
   
super.onCreate(savedInstanceState);
   
instance = this;
    SetSplash();
   

}

3.闪屏图放到mipmap下:

 

4.AndroidManifest.xml设置theme:

<activity android:name="com.unity3d.player.MainActivity" android:process=":UnityActivity" android:theme="@style/UnityThemeSelector" android:screenOrientation="fullSensor" android:launchMode="standard" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">

  <
meta-data android:name="unityplayer.UnityActivity" android:value="true" />
  <
meta-data android:name="android.notch_support" android:value="true" />
  <
meta-data android:name="android.notch_support" android:value="true" />
</
activity>

Styles.xml可以修改主题背景色或背景图:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<
style name="UnityThemeSelector" parent="BaseUnityTheme">
   <
item name="android:windowBackground">@android:color/white</item>
</style>
<
style name="BaseUnityTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
</
style>
<
style name="UnityThemeSelector.Translucent" parent="@style/UnityThemeSelector">
    <
item name="android:windowIsTranslucent">true</item>
    <
item name="android:windowBackground">@android:color/transparent</item>
</
style>
</
resources>

二、unity配置

1.unity里取消闪屏,File - Build Settings - Player Settings -Splash Image:

 

1.unity在需要关闭闪屏的cs代码处增加一个关闭调用方法:

try

            {

                AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.MainActivity");//unity对应android主类

                AndroidJavaObject jo = jc.CallStatic<AndroidJavaObject>("GetInstance");//取到Activity对象

                jo.Call("HideSplash");//调用MainActivity的HideSplash方法

            }

            catch (Exception e)

            {

            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值