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

相关推荐
木子庆五2 分钟前
Android设计模式之代理模式
android·设计模式·代理模式
在雨季等你18 分钟前
创业之旅 - 反思 - 整改 - 新的方向 - 诚邀
android
Long_poem33 分钟前
【自学笔记】PHP语言基础知识点总览-持续更新
android·笔记·php
lichao8904271 小时前
JBDev - Theos下一代越狱开发工具
ios
fatiaozhang95272 小时前
晶晨S905L3A(B)-安卓9.0-开启ADB和ROOT-支持IPTV6-支持外置游戏系统-支持多种无线芯片-支持救砖-完美通刷线刷固件包
android·游戏·adb·华为·电视盒子·机顶盒rom·魔百盒固件
行墨3 小时前
Kotlin语言的==与===比较操作
android
圣火喵喵教3 小时前
Pixel 8 pro 刷AOSP源码 Debug 详细教程(含救砖)
android
二流小码农4 小时前
鸿蒙开发:使用Ellipse绘制椭圆
android·ios·harmonyos
自不量力的A同学4 小时前
谷歌将 Android OS 完全转变为 “内部开发”
android
行墨4 小时前
Kotlin 的可空类型
android