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

相关推荐
aningxiaoxixi37 分钟前
Android 之 audiotrack
android
枷锁—sha39 分钟前
【DVWA系列】——CSRF——Medium详细教程
android·服务器·前端·web安全·网络安全·csrf
mascon1 小时前
U3D打包IOS的自我总结
ios
向宇it1 小时前
【unity组件介绍】URP Decal Projector贴花投影器,将特定材质(贴花)投影到场景中的其他对象上。
游戏·3d·unity·c#·游戏引擎·材质
名字不要太长 像我这样就好1 小时前
【iOS】继承链
macos·ios·cocoa
karshey2 小时前
【IOS webview】IOS13不支持svelte 样式嵌套
ios
潜龙95272 小时前
第4.3节 iOS App生成追溯关系
macos·ios·cocoa
Cao_Shixin攻城狮4 小时前
Flutter运行Android项目时显示java版本不兼容(Unsupported class file major version 65)的处理
android·java·flutter
呼啦啦呼啦啦啦啦啦啦7 小时前
利用pdfjs实现的pdf预览简单demo(包含翻页功能)
android·javascript·pdf
idjl9 小时前
Mysql测试题
android·adb