当前位置:   article > 正文

AssetBundle-关于Mainfest文件使用_loadassetbundlemainfest

loadassetbundlemainfest

在这里插入图片描述

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.Networking;
/*
 * Author:W
 * mainfenst文件
 */
public class AssetBundleManager : MonoBehaviour
{
    private AssetBundle shareAb = null;
    private AssetBundle ab = null;

    // Start is called before the first frame update
    void Start()
    {
                
        //加载mainfest的AB包。并获取到其中mainfest文件,从而知晓项目中所有AB包以及他们之间的依赖关系
        AssetBundle assetBundle = LoadAssetBundleFromFile("AssetBundles/AssetBundles");
        AssetBundleManifest assetBundleManifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

        //打印所有AB名
        foreach (string abName in assetBundleManifest.GetAllAssetBundles())
        {
            Debug.Log("AB包名:"+abName);
        }

        //获取cubewall包依赖的所有AB包,并进行加载
        string[] depenABs = assetBundleManifest.GetAllDependencies("walls/cubewall.unityobj");
        foreach (string name in depenABs)
        {
            Debug.Log("walls/cubewall.unityobj包所依赖的包:"+name);
            LoadAssetBundleFromFile("AssetBundles/"+name);
        }

        //再加载cubewall包本身
        AssetBundle wallAB = LoadAssetBundleFromFile("AssetBundles/walls/cubewall.unityobj");

        //实例化
        GameObject wallPrefab = wallAB.LoadAsset<GameObject>("CubeWall");
        Instantiate(wallPrefab);

    }

    /// <summary>
    /// AB加载方式2:从本地文件夹中加载【同步】
    /// </summary>
    /// <returns></returns>
    private AssetBundle LoadAssetBundleFromFile(string path)
    {
        AssetBundle ab = null;

        ab = AssetBundle.LoadFromFile(path);

        return ab;
    }
    
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号