Unity 使用Android Splash

java代码

    ImageView bgView=null;
    //显示启动图 
    void ShowSplash() {
       try {
              //对应unity目录:
          InputStream is = getAssets().open("bin/Data/splash.png");
          Bitmap splashBitmap = null;
          BitmapFactory.Options options = new BitmapFactory.Options();
          options.inPreferredConfig = Bitmap.Config.ARGB_8888;
          splashBitmap = BitmapFactory.decodeStream(is, null, options);
          is.close();
          bgView = new ImageView(this);
          bgView.setImageBitmap(splashBitmap);
          bgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        Resources r = mUnityPlayer.currentActivity.getResources();
          mUnityPlayer.addView(bgView);       
//        mUnityPlayer.addView(bgView, r.getDisplayMetrics().widthPixels, r.getDisplayMetrics().heightPixels);
      } catch (Exception e) {
          Log.v("unity", "Exception while load splash:" + e.toString());
      }
    }

    //关闭启动图 
    void HideSplash() {
       this.runOnUiThread(new Runnable() {
           @Override
          public void run() {
              mUnityPlayer.removeView(bgView);
              bgView = null;
          }
       });
    }

splash.png文件放在unity工程中的目录为:
image.png

该文件不用放到android的插件工程中,直接放在unity中就可以了

这里有个bug:splash在加载第0个场景时会被隐藏或者销毁掉没有仔细测试,然后加载场景过程中是黑屏

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,548评论 25 708
  • 翻译:莫铭原文地址:AssetBundle usage patterns 本系列中的上一篇文章覆盖了AssetBu...
    莫铭阅读 5,386评论 1 12
  • 才女张爱玲曾在送给胡兰成的照片背面写到,遇见她,她变得很低很低,一直低到尘埃里去,但她的心是欢喜的,并且在那里开...
    怎么大风这么狠阅读 1,120评论 0 0
  • 昨晚睡前又做了了几下虎瓜功,晚上睡的很香,但凌晨感觉后心凉,身体这层层寒气,出来的慢长而不易。 早餐吃的饱饱去上书...
    王悦yue阅读 279评论 1 5
  • 幸福的婚姻,离不开两个人的经营。而在这经营中,丈夫的态度对婚姻的影响尤其关键。女人很柔软,只要你心里装着她,哪怕是...
    深夜她故事阅读 693评论 0 12