杀鸡焉用牛刀 发表于 2025-1-9 12:51:54

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

Ios篇

在Xcode中创建Storyboard文件,2019及之之前版本应该是XIB文件,创建方法
在Unity-IPione先创建一个文件夹定名为View 啥都行 然后把图篇资源拉进来
https://i-blog.csdnimg.cn/direct/0d48293efd874b2882ae6a22646577aa.png
然后创建
https://i-blog.csdnimg.cn/direct/36679e8279494073acf535367c9938be.png
Storyboard就是第二个 XIB就是第三个
https://i-blog.csdnimg.cn/direct/7926577fc7c14ed1a65bdf594b88299e.png
需要创建两个 一个是手机 是个是pad
然后点击 右上角的+ 创建一个ImageView 拉到xib内里 右侧选择图 然后选择适配
左边箭头选择图 右边箭头适配
https://i-blog.csdnimg.cn/direct/2b369c5489e647a08e2478e1a5cf32f7.png
一般需要两个图 一个是底图 一个是logo
然后在Unity中选择创建的这两个文件
https://i-blog.csdnimg.cn/direct/1540d59ccbde46098c1fa2604506db2e.png
然后打包测试
ps:如果修改的话需要重新打包
安卓篇

在StreamingAssets放两张图
https://i-blog.csdnimg.cn/direct/b10b48d3ddc5484094114494f9eb8b46.png
然后编辑MainActivity.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;
      privateImageView bgView = null;
         FrameLayout frameLayout = null ;
onCreate中调用showSplash
protected void onCreate(Bundle bundle) {
      Log.d("Unity", "MainActivity On Create");
      super.onCreate(bundle);
         showSplash();
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("" + 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("" + e.toString());
            }
      }
在C#中等展示完loading下一帧hideSplash,如许就实现了全屏底图+居中适配向上偏移461的logo
https://i-blog.csdnimg.cn/direct/b055e023afe640629a731d51e7d8ce5f.png

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Unnity IOS安卓启动黑屏加图(底图+Logo gif也行)