示例#1
0
 /// <summary>
 /// 单利类
 /// </summary>
 /// <returns></returns>
 public static LoadABManiFest GetInstance()
 {
     if (_instance == null)
     {
         _instance = new LoadABManiFest();
     }
     return(_instance);
 }
    /// <summary>
    /// 清单文件
    /// </summary>
    /// <param name="dataName"></param>
    /// <param name="callBack"></param>
    /// <returns></returns>
    public IEnumerator LoadAssetBundlePack(LoadABDataCompleteHandle callBack)
    {
        //等待maniFest清单文件加载完成
        while (!LoadABManiFest.GetInstance()._isLoadManiFestFinshed)
        {
            yield return(null);
        }
        _currentManiFest = LoadABManiFest.GetInstance().GetABManiFest();
        if (_currentManiFest == null)
        {
            Debug.LogError(GetType() + "\t   _currentManiFest      为空   ");
            yield return(null);
        }
        string[] abName = LoadABManiFest.GetInstance().GetAllABName();


        for (int i = 0; i < abName.Length; i++)
        {
            string[] name = abName[i].Split('.');
            Debug.Log("ab包的名字:\t" + name[0]);
        }


        for (int i = 0; i < abName.Length; i++)
        {
            string[] name = abName[i].Split('.');
            if (!_DicAllAB.ContainsKey(name[0]))
            {
                Debug.Log("存储加载的 ab资源:\t" + name[0]);
                LoadAssetBundle loadAB = new LoadAssetBundle(name[0]);
                _DicAllAB.Add(name[0], loadAB);
            }
        }
        Debug.Log("一共存储了这么多个  ab包:\t" + _DicAllAB.Count);

        for (int i = 0; i < abName.Length; i++)
        {
            string[] name = abName[i].Split('.');
            Debug.Log(name[0]);
            if (_DicAllAB.ContainsKey(name[0]))
            {
                LoadAssetBundle loadAB = _DicAllAB[name[0]];
                yield return(loadAB.LoadAssetBundleIE());
            }
        }
        ///此时调用委托  全局只调用一次
        if (callBack != null)
        {
            callBack();
        }
    }
 private void Awake()
 {
     StartCoroutine(LoadABManiFest.GetInstance().LoadManiFest());
 }