zoukankan      html  css  js  c++  java
  • 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);
    }

    }

  • 相关阅读:
    java中使用MD5加密的算法
    [转]自定义注释@interface的用法
    [转]Spring IOC详解
    [转]sed命令详解
    SimpleDateFormat线程不安全问题处理
    Unable to locate the Javac Compiler 解决办法
    MySQL ERROR 1045错误解决办法
    Python装饰器学习(九步入门)
    python 可变参数函数定义* args和**kwargs的用法
    如何更好的利用Node.js的性能极限
  • 原文地址:https://www.cnblogs.com/qipei/p/9885451.html
Copyright © 2011-2022 走看看