Unnity IOS安卓启动黑屏加图(底图+Logo gif也行)

打印 上一主题 下一主题

主题 887|帖子 887|积分 2661

Ios篇

在Xcode中创建Storyboard文件,2019及之之前版本应该是XIB文件,创建方法
在Unity-IPione先创建一个文件夹定名为View 啥都行 然后把图篇资源拉进来

然后创建

Storyboard就是第二个 XIB就是第三个

需要创建两个 一个是手机 是个是pad
然后点击 右上角的+ 创建一个ImageView 拉到xib内里 右侧选择图 然后选择适配
左边箭头选择图 右边箭头适配

一般需要两个图 一个是底图 一个是logo
然后在Unity中选择创建的这两个文件

然后打包测试
ps:如果修改的话需要重新打包
安卓篇

在StreamingAssets放两张图

然后编辑MainActivity.java
  1. import android.graphics.Color;
  2. // import android.graphics.Point;
  3. import android.view.ViewGroup;
  4. // import android.view.animation.AlphaAnimation;
  5. // import android.view.animation.Animation;
  6. import android.widget.ImageView;
  7. import android.content.res.Resources;
  8. import android.util.DisplayMetrics;
  9. import android.hardware.Sensor;
  10. import android.hardware.SensorManager;
  11. import java.io.InputStream;
  12. import android.graphics.Bitmap;
  13. import android.graphics.BitmapFactory;
  14. import android.widget.FrameLayout;
复制代码
  1.         private  ImageView bgView = null;
  2.          FrameLayout frameLayout = null ;
复制代码
onCreate中调用showSplash
  1.   protected void onCreate(Bundle bundle) {
  2.         Log.d("Unity", "MainActivity On Create");
  3.         super.onCreate(bundle);
  4.            showSplash();
复制代码
  1.   public void showSplash() {
  2.             try {
  3.                   if (frameLayout == null){
  4.                     hideSplash();
  5.                 }
  6.                 DisplayMetrics outMetrics = new DisplayMetrics();
  7.                 WindowManager wm = (WindowManager) mUnityPlayer.currentActivity.getSystemService(Context.WINDOW_SERVICE);
  8.                 wm.getDefaultDisplay().getRealMetrics(outMetrics);
  9.              //   bgView = new ImageView(this);
  10.                 //--使用纯色背景---
  11.                  //bgView.setBackgroundColor(Color.parseColor("#5633AB"));//--
  12.                 //--使用使用纯色背景 END---
  13.                     //--使用png---
  14.               // 创建 FrameLayout 作为容器
  15.                    frameLayout = new FrameLayout(this);
  16.            
  17.                    // 设置底图(背景)
  18.                    bgView = new ImageView(this);
  19.                    InputStream is = mUnityPlayer.currentActivity.getAssets().open("loadBackground.jpg");
  20.                    Bitmap bm = BitmapFactory.decodeStream(is);
  21.                    bgView.setImageBitmap(bm);
  22.                    bgView.setScaleType(ImageView.ScaleType.FIT_XY);
  23.            
  24.                    // 将底图的宽高设置为屏幕宽高
  25.                    FrameLayout.LayoutParams bgParams = new FrameLayout.LayoutParams(outMetrics.widthPixels, outMetrics.heightPixels);
  26.                    frameLayout.addView(bgView, bgParams);
  27.            
  28.                    // 设置 logo 图片
  29.                    ImageView logoView = new ImageView(this);
  30.                    InputStream logoStream = mUnityPlayer.currentActivity.getAssets().open("logo.png");
  31.                    Bitmap logoBitmap = BitmapFactory.decodeStream(logoStream);
  32.                    logoView.setImageBitmap(logoBitmap);
  33.                    logoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
  34.            
  35.                    // 设置 logo 的布局参数(居中且向上偏移 461 像素)
  36.                    FrameLayout.LayoutParams logoParams = new FrameLayout.LayoutParams(
  37.                            FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT
  38.                    );
  39.                    logoParams.gravity = android.view.Gravity.CENTER;
  40.                    logoParams.topMargin = -461; // 向上偏移 461 像素
  41.                    frameLayout.addView(logoView, logoParams);
  42.            
  43.                    // 将 FrameLayout 添加到 Unity Player 中
  44.                    mUnityPlayer.addView(frameLayout, outMetrics.widthPixels, outMetrics.heightPixels);
  45.                
  46.    
  47.                 //--使用Gif---
  48.     //             gv = new GifImageView(mUnityPlayer.currentActivity);
  49.     //             gv.setMovie(mUnityPlayer.currentActivity.getAssets().open("loadAnimation.gif"),realScreenWidth / 2 - 353,realScreenHeight / 2-353);
  50.     //             gv.setScaleType(ImageView.ScaleType.CENTER);
  51.     //             mUnityPlayer.addView(gv, realScreenWidth, realScreenHeight);
  52.                  //--使用Gif END---
  53.                 //Log.v("test",p.x+"");
  54.    
  55.    
  56.             } catch (Exception e) {
  57.                 // error("[onShowSplash]" + e.toString());
  58.             }
  59.         }
  60.    
  61.         /**
  62.          * 隐藏splash
  63.          */
  64.         public void hideSplash() {
  65.             try {
  66.               if (frameLayout == null)  // 先检查 frameLayout 是否存在
  67.                          return;
  68.             
  69.                      runOnUiThread(new Runnable() {
  70.                          public void run() {
  71.                              // 移除整个 FrameLayout(包括 bgView 和 logoView)
  72.                              mUnityPlayer.removeView(frameLayout);
  73.                              frameLayout = null;
  74.                          }
  75.                      });
  76.             } catch (Exception e) {
  77.                 // error("[onHideSplash]" + e.toString());
  78.             }
  79.         }
复制代码
在C#中等展示完loading下一帧hideSplash,如许就实现了全屏底图+居中适配向上偏移461的logo


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

杀鸡焉用牛刀

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表