勾选显示splash,然后用原生添加显示splash
public class UnityPlayerActivity extends Activity
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Setup activity layout
@Override protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBX_8888); //
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
UnitySplashSDK.getInstance().onCreate(this,savedInstanceState);
}
public void HideSplash()
{
Log.d("UnityPlayer","Android_HideSplash");
UnitySplashSDK.getInstance().onHideSplash();
}package com.aiiage.steam.evolve;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.media.Image;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import com.unity3d.player.UnityPlayer;
public class UnitySplashSDK {
ImageView bgView = null;
UnityPlayer mUnityPlayer = null;
static UnitySplashSDK mInstance;
public static UnitySplashSDK getInstance()
{
if(mInstance==null)
{
synchronized (UnitySplashSDK.class)
{
if(mInstance == null)
{
mInstance = new UnitySplashSDK();
}
}
}
return mInstance;
}
public void onCreate(Activity activity, Bundle savedInstanceState)
{
mUnityPlayer = ((UnityPlayerActivity)activity).mUnityPlayer;
onShowSplash();
SetProgressBar(activity);
}
void onShowSplash()
{
if(bgView!=null)return;
try
{
Log.d("","UnityActivity_onShowSplash");
bgView = new ImageView(UnityPlayer.currentActivity);
bgView.setBackgroundColor(Color.parseColor("#36c3e5"));
bgView.setBackgroundResource(R.drawable.unity_static_splash);
bgView.setScaleType(ImageView.ScaleType.CENTER);
Resources r = mUnityPlayer.currentActivity.getResources();
mUnityPlayer.addView(bgView,r.getDisplayMetrics().widthPixels , r.getDisplayMetrics().heightPixels);
}
catch (Exception e)
{
e.printStackTrace();
}
}
ProgressBar barshow;
public void SetProgressBar(Activity mainActivity)
{
Log.d("SetProgressBar_","SetProgressBar:"+mainActivity.getLocalClassName());
barshow = new ProgressBar(mUnityPlayer.currentActivity, null, android.R.attr.progressBarStyleLarge);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(10,10);
barshow.setLayoutParams(lp);
WindowManager wm = (WindowManager) mainActivity.getSystemService(Context.WINDOW_SERVICE);
int w = wm.getDefaultDisplay().getWidth()/2;
int h = wm.getDefaultDisplay().getHeight()/2;
barshow.setPadding(10, 10,20,20);
mUnityPlayer.addView(barshow);
}
public void onHideSplash()
{
try
{
if(bgView==null)return;
Log.d("","UnityActivity_onHideSplash");
UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mUnityPlayer.removeView(bgView);
bgView = null;
if(barshow!=null)
{
mUnityPlayer.removeView(barshow);
barshow = null;
}
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
}
}