• AB打包Day02


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class LoadMan : MonoBehaviour {

    // Use this for initialization
    public string ABName;
    string _abPath ;

    string _manPath;
    private List<AssetBundle> ManListAB;

    void Start ()
    {
    ManListAB = new List<AssetBundle>();
    //capsulepre
    //www
    _abPath = Application.streamingAssetsPath + "/Windows/";
    _manPath = Application.streamingAssetsPath + "/Windows/Windows";

    //不管啥 应该查找依赖关系

    #region 加载依赖

    AssetBundle _manAB = AssetBundle.LoadFromFile(_manPath);
    //固定格式
    AssetBundleManifest manifest = _manAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

    string[] dependencies = manifest.GetAllDependencies(ABName);
    //加载依赖

    if(dependencies.Length != 0)
    foreach (string s in dependencies)
    {
    //挨个加载依赖关系
    ManListAB.Add(LoadABByName(s)); // 存在内存中
    }

    #endregion


    //依赖加载完毕 圆柱和立方体
    AssetBundle _ab = AssetBundle.LoadFromFile(_abPath+ABName);
    GameObject copyObj = _ab.LoadAsset<GameObject>("Capsule");
    Instantiate(copyObj);
    //释放ab依赖的内存

    foreach (var v in ManListAB)
    {
    v.Unload(false);
    }

    _ab.Unload(false); // 不从场景里面剔除
    //true 场景剔除

    AssetBundle _ab01 = AssetBundle.LoadFromFile(_abPath+ABName); //_ab.Unload(false); 没有这句话会重复加载
    GameObject copyObj01 = _ab01.LoadAsset<GameObject>("Capsule");
    Instantiate(copyObj01,Vector3.one,Quaternion.identity);

    }

    // Update is called once per frame
    void Update () {

    }

    private AssetBundle LoadABByName(string name)
    {
    return AssetBundle.LoadFromFile(_abPath + name);
    }

    }

  • 相关阅读:
    多线程交替打印示例
    单列集合框架体系Collection
    同域名下,两个网站通过cookie共享登录注册功能大概思路。
    CSS 隐藏滚动条
    Vue3--组件间传值
    TypeScript--类(class)
    TypeScript--泛型(generic)
    理解LDAP与LDAP注入
    CRLF injection 简单总结
    pigctf期末测评
  • 原文地址:https://www.cnblogs.com/qipei/p/9885451.html
Copyright © 2020-2023  润新知