예제 #1
0
    /// <summary>
    /// 加载 依赖 资源 信息
    /// </summary>
    static void LoadAssetBundleDependencies(string sABName, List <string> sResult)
    {
        if (null == _manifest)
        {
            return;
        }
        UtilLoadAssetsDataAssetBundle assetload = null;

        string[] dependencies = _manifest.GetAllDependencies(sABName);
        for (int index = 0; null != dependencies && index < dependencies.Length; index++)
        {
            string url = string.Intern(dependencies[index]);
            if (!_hash_list.ContainsKey(dependencies[index]))
            {
                assetload = new UtilLoadAssetsDataAssetBundle(url, true);
                _assets_will_load.Add(assetload);
                /// 地址指针指向这个数组
                _hash_list.Add(url, _assets_will_load);
                _hash_data.Add(url, assetload);
            }
            /// 计数器累加
            else
            {
                (_hash_data[url] as UtilLoadAssetsDataAssetBundle).dependenciesCount++;
            }
            sResult.Add(url);
            /// 我不想做递归的
            /// 但是这样最省事。。。。
            /// 好烦!!!
            /// 貌似能开的接口能全部搞定,爽呀!!!!
            //LoadAssetBundleDependencies(url, sResult);
        }
        /// 加载
    }
예제 #2
0
    /// <summary>
    /// 初始化函数
    /// </summary>
    public static void Init()
    {
        if (null != _instance)
        {
            return;
        }
        GameObject obj = new GameObject("____UtilLoadAssets");

        _instance = obj.AddComponent <UtilLoadAssets>();
        UnityEngine.Object.DontDestroyOnLoad(obj);
        /// 获取 manifest
        string path_manifest = UtilLoadAssetsDataAssetBundle.PathReal("assetsbundle");

        try
        {
#if UNITY_EDITOR
            if (!System.IO.File.Exists(path_manifest))
            {
                return;
            }
#endif
            AssetBundle manifestAB = AssetBundle.LoadFromFile(path_manifest);
            string[]    names      = manifestAB.GetAllAssetNames();
            _manifest = manifestAB.LoadAsset <AssetBundleManifest>(names[0]);
        }
        catch { Debug.LogError(string.Format("Error : Undfind manifest file = {0}", path_manifest)); }
    }
예제 #3
0
    public static void LoadAssetBundleAsync(List <string> sUrlList, UtilLoadAssetsFunction sSucceed, UtilLoadAssetsFunction sError)
    {
        UtilLoadAssetsDataAssetBundle assetload = null;
        List <string> dependencies = new List <string>();

        for (int index = 0; index < sUrlList.Count; index++)
        {
            string url = string.Intern(sUrlList[index].ToLower());
            if (!_hash_list.ContainsKey(url))
            {
                assetload = new UtilLoadAssetsDataAssetBundle(url);
                _assets_will_load.Add(assetload);
                /// 地址指针指向这个数组
                _hash_list.Add(url, _assets_will_load);
                _hash_data.Add(url, assetload);

                /// 对依赖文件进行处理操作
                LoadAssetBundleDependencies(url, dependencies);
            }
        }
        /// 对 回调处理
        if (null != sSucceed || null != sError)
        {
            HD hd = new HD(sUrlList, sSucceed, sError);
            hd.dependencies = dependencies;
            _list_hd.Add(hd);
        }
    }