从《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() {@Overridepublic 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)
{
}