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

Ios篇

在Xcode中创建Storyboard文件,2019及之之前版本应该是XIB文件,创建方法

在Unity-IPione先创建一个文件夹命名为View 啥都行 然后把图篇资源拉进来

然后创建

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

需要创建两个 一个是手机 是个是pad

然后点击 右上角的+ 创建一个ImageView 拉到xib里面 右侧选择图 然后选择适配

左边箭头选择图 右边箭头适配

一般需要两个图 一个是底图 一个是logo

然后在Unity中选择创建的这两个文件

然后打包测试

ps:如果修改的话需要重新打包

安卓篇

在StreamingAssets放两张图

然后编辑MainActivity.java

java 复制代码
import android.graphics.Color;
// import android.graphics.Point;
import android.view.ViewGroup;
// import android.view.animation.AlphaAnimation;
// import android.view.animation.Animation;
import android.widget.ImageView;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.FrameLayout;
java 复制代码
        private  ImageView bgView = null;
         FrameLayout frameLayout = null ;

onCreate中调用showSplash

java 复制代码
  protected void onCreate(Bundle bundle) {
        Log.d("Unity", "MainActivity On Create");
        super.onCreate(bundle);
           showSplash();
java 复制代码
  public void showSplash() {
            try {
                  if (frameLayout == null){
                    hideSplash();
                }
                DisplayMetrics outMetrics = new DisplayMetrics();
                WindowManager wm = (WindowManager) mUnityPlayer.currentActivity.getSystemService(Context.WINDOW_SERVICE);
                wm.getDefaultDisplay().getRealMetrics(outMetrics);
             //   bgView = new ImageView(this);
                //--使用纯色背景---
                 //bgView.setBackgroundColor(Color.parseColor("#5633AB"));//--
                //--使用使用纯色背景 END---
                    //--使用png---
              // 创建 FrameLayout 作为容器
                   frameLayout = new FrameLayout(this);
           
                   // 设置底图(背景)
                   bgView = new ImageView(this);
                   InputStream is = mUnityPlayer.currentActivity.getAssets().open("loadBackground.jpg");
                   Bitmap bm = BitmapFactory.decodeStream(is);
                   bgView.setImageBitmap(bm);
                   bgView.setScaleType(ImageView.ScaleType.FIT_XY);
           
                   // 将底图的宽高设置为屏幕宽高
                   FrameLayout.LayoutParams bgParams = new FrameLayout.LayoutParams(outMetrics.widthPixels, outMetrics.heightPixels);
                   frameLayout.addView(bgView, bgParams);
           
                   // 设置 logo 图片
                   ImageView logoView = new ImageView(this);
                   InputStream logoStream = mUnityPlayer.currentActivity.getAssets().open("logo.png");
                   Bitmap logoBitmap = BitmapFactory.decodeStream(logoStream);
                   logoView.setImageBitmap(logoBitmap);
                   logoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
           
                   // 设置 logo 的布局参数(居中且向上偏移 461 像素)
                   FrameLayout.LayoutParams logoParams = new FrameLayout.LayoutParams(
                           FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT
                   );
                   logoParams.gravity = android.view.Gravity.CENTER;
                   logoParams.topMargin = -461; // 向上偏移 461 像素
                   frameLayout.addView(logoView, logoParams);
           
                   // 将 FrameLayout 添加到 Unity Player 中
                   mUnityPlayer.addView(frameLayout, outMetrics.widthPixels, outMetrics.heightPixels);
                
    
                //--使用Gif---
    //             gv = new GifImageView(mUnityPlayer.currentActivity);
    //             gv.setMovie(mUnityPlayer.currentActivity.getAssets().open("loadAnimation.gif"),realScreenWidth / 2 - 353,realScreenHeight / 2-353);
    //             gv.setScaleType(ImageView.ScaleType.CENTER);
    //             mUnityPlayer.addView(gv, realScreenWidth, realScreenHeight);
                 //--使用Gif END---
                //Log.v("test",p.x+"");
    
    
            } catch (Exception e) {
                // error("[onShowSplash]" + e.toString());
            }
        }
    
        /**
         * 隐藏splash
         */
        public void hideSplash() {
            try {
              if (frameLayout == null)  // 先检查 frameLayout 是否存在
                         return;
             
                     runOnUiThread(new Runnable() {
                         public void run() {
                             // 移除整个 FrameLayout(包括 bgView 和 logoView)
                             mUnityPlayer.removeView(frameLayout);
                             frameLayout = null;
                         }
                     });
            } catch (Exception e) {
                // error("[onHideSplash]" + e.toString());
            }
        }

在C#中等展示完loading下一帧hideSplash,这样就实现了全屏底图+居中适配向上偏移461的logo

相关推荐
千里马学框架12 小时前
一起学 Android 14:ShellTransition 屏幕旋转过程深度剖析
android·智能手机·性能优化·framework·性能·屏幕旋转·rotation
美狐美颜SDK开放平台12 小时前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk
AFinalStone13 小时前
Android7 SystemUI源码解析(七)Keyguard锁屏模块深度解析
android·systemui
致远ccc13 小时前
Google Play 上架前如何测试 App?多国家 Android 环境测试
android·app测试·googleplay·多国家应用测试
ttyyttemo15 小时前
Kotlin 协程中的 Job 结构化并发与取消
android
sun00770015 小时前
tbox 4g/5g切换,导致wan ip 改变,导致车机旧网络不可用。需要重启车机才行
android
其实防守也摸鱼16 小时前
内网穿透与反向代理:原理、工具与实战指南
android·大数据·运维·安全·网络安全·自动化·渗透
魔士于安16 小时前
unity 丑陋哥布林 哥布林有humannoid 动画没 带动画
unity·游戏引擎·材质·贴图·模型
茶底世界之下17 小时前
为什么预览、录制、离线导出不能共享同一个背压策略?
ios·swift
AFinalStone17 小时前
Android7 SystemUI 源码解析(四)NavigationBar 导航栏与 SystemBars
android·systemui