Esempio n. 1
0
        // 加载依赖资源
        // Where we get all the dependencies and load them all.
        void LoadDependencies(string assetBundleName)
        {
            if (m_AssetBundleManifest == null)
            {
                Debug.LogError("Please initialize AssetBundleManifest by calling AssetBundleManager.Initialize()");
                return;
            }

            // Get dependecies from the AssetBundleManifest object..
            string[] dependencies = m_AssetBundleManifest.GetAllDependencies(assetBundleName);
            if (dependencies.Length == 0)
            {
                return;
            }

            // 查找别名
//			for (int i = 0; i < dependencies.Length; i++)
//				dependencies[i] = RemapVariantName(dependencies[i]);

            // Record and load all dependencies.
            m_Dependencies.Add(assetBundleName, dependencies);
            for (int i = 0; i < dependencies.Length; i++)
            {
                AFileInfo fileInfo = GetFileInfo(dependencies[i]);
                if (fileInfo != null)
                {
                    LoadAssetBundleInternal(fileInfo);
                }
                else
                {
                    Debug.LogError("没有找到依赖的文件 " + dependencies[i]);
                }
            }
        }
Esempio n. 2
0
        // 检测是否已经创建了WWW,没有就创建WWW
        // Where we actuall call WWW to download the assetBundle.
        bool LoadAssetBundleInternal(AFileInfo fileInfo)
        {
            // Already loaded.
            AssetBundleInfo bundle = null;

            m_LoadedAssetBundles.TryGetValue(fileInfo.assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.referencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingWWWs.ContainsKey(fileInfo.assetBundleName))
            {
                return(true);
            }

            WWW    download = null;
            string url      = assetManager.GetRealURL(fileInfo.path);

            download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(fileInfo.assetBundleName), 0);
            m_DownloadingWWWs.Add(fileInfo.assetBundleName, download);

            return(false);
        }
Esempio n. 3
0
        void InitManifest()
        {
            assetBundleManager = new AssetBundleManager(this);
            assetBundleManagerList.Add(assetBundleManager);

            foreach (KeyValuePair <string, AFileInfo> kvp in manifestFileInfoDict)
            {
                AFileInfo fileInfo = kvp.Value;
                Debug.Log(kvp.Key);
                ManifestAssetBundleManager manifestAssetBundleManager = new ManifestAssetBundleManager(this, fileInfo.manifestName, fileInfo.path, manifestFileListDict[fileInfo.manifestName]);
                manifestAssetBundleManagerDict.Add(manifestAssetBundleManager.manifestName, manifestAssetBundleManager);
                assetBundleManagerList.Add(manifestAssetBundleManager);
            }
            manifestCount           = manifestAssetBundleManagerDict.Count;
            assetBundleManagerCount = assetBundleManagerList.Count;

            foreach (KeyValuePair <string, ManifestAssetBundleManager> kvp in manifestAssetBundleManagerDict)
            {
                kvp.Value.LoadManifest();
            }

            if (manifestCount == 0)
            {
                PrepareFinal();
            }
        }
Esempio n. 4
0
        void Load(AFileInfo fileInfo, Action <string, System.Object, System.Object> callback, System.Object arg, Type type)
        {
            ManifestAssetBundleManager manifest;

            if (!string.IsNullOrEmpty(fileInfo.manifestName) && manifestAssetBundleManagerDict.TryGetValue(fileInfo.manifestName, out manifest))
            {
                manifest.LoadAsset(fileInfo, callback, arg, type);
            }
            else
            {
                assetBundleManager.LoadAsset(fileInfo, callback, arg, type);
            }
        }
Esempio n. 5
0
        void Unload(AFileInfo fileInfo, bool force)
        {
            ManifestAssetBundleManager manifest;

            if (!string.IsNullOrEmpty(fileInfo.manifestName) && manifestAssetBundleManagerDict.TryGetValue(fileInfo.manifestName, out manifest))
            {
                manifest.UnloadAssetBundle(fileInfo.assetBundleName, force);
            }
            else
            {
                assetBundleManager.UnloadAssetBundle(fileInfo.assetBundleName, force);
            }
        }
Esempio n. 6
0
        //  加载”资源包“和他依赖的资源包
        // Load AssetBundle and its dependencies.
        void LoadAssetBundle(AFileInfo fileInfo)
        {
            // 查找别名
//			string assetBundleName = RemapVariantName(fileInfo.assetBundleName);

            // Check if the assetBundle has already been processed.
            bool isAlreadyProcessed = LoadAssetBundleInternal(fileInfo);

            // Load dependencies.
            if (!isAlreadyProcessed)
            {
                LoadDependencies(fileInfo.assetBundleName);
            }
        }
Esempio n. 7
0
        IEnumerator OnLoadAsset(AFileInfo fileInfo, Action <string, System.Object, System.Object> callback, System.Object arg, Type type)
        {
            LoadAssetBundle(fileInfo);

            AssetBundleLoadAssetOperation request = new AssetBundleLoadAssetOperation(this, fileInfo.assetBundleName, fileInfo.assetName, type);

            m_InProgressOperations.Add(request);
            yield return(StartCoroutine(request));

            if (callback != null)
            {
                System.Object obj = request.GetAsset();
                callback(fileInfo.name, obj, arg);
            }
        }
Esempio n. 8
0
        //--------------------------

        IEnumerator LoadExe(AFileInfo fileInfo, Action <string, System.Object, System.Object> callback, System.Object arg, Type type, bool isAsync)
        {
            string filename = fileInfo.name;

            if (fileInfo.loadType == ALoadType.Resource)
            {
                System.Object obj = null;
                if (isAsync == false)
                {
                    obj = Resources.Load(fileInfo.path, type);
                }

                else
                {
                    ResourceRequest resourceRequest = Resources.LoadAsync(fileInfo.path, type);
                    yield return(resourceRequest);

                    obj             = resourceRequest.asset;
                    resourceRequest = null;
                }

                if (callback != null)
                {
                    callback(filename, obj, arg);
                }

                if (!fileInfo.caches.ContainsKey(type))
                {
                    fileInfo.caches.Add(type, obj);
                }
                obj = null;
                preloads.Add(fileInfo);
            }
            else
            {
                WWW www = new WWW(GetRealURL(fileInfo.path));
                yield return(www);

                if (string.IsNullOrEmpty(www.error))
                {
                    if (www.text != null)
                    {
                        fileInfo.obj = www.text;
                    }
                    else if (www.texture != null)
                    {
                        fileInfo.obj = www.texture;
                    }
                    else if (www.audioClip != null)
                    {
                        fileInfo.obj = www.audioClip;
                    }
                    else
                    {
                        fileInfo.obj = www.bytes;
                    }

                    if (callback != null)
                    {
                        callback(filename, fileInfo.obj, arg);
                    }

                    preloads.Add(fileInfo);
                }
                else
                {
                    fileInfo.status = AStatusType.Errored;
                    Debug.LogWarning("[AssetMananger]\t加载资源出错 name=" + filename + "   fileInfo=" + fileInfo + "   www.error=" + www.error);
                }

                www.Dispose();
                www = null;
            }
        }
Esempio n. 9
0
        private void ParseInfo(string p, ALoadType loadType)
        {
            using (StringReader stringReader = new StringReader(p))
            {
                bool isEditor = Application.isEditor;
                //stringReader.ReadLine();
                while (stringReader.Peek() >= 0)
                {
                    string line = stringReader.ReadLine();
                    if (!string.IsNullOrEmpty(line))
                    {
                        string[] seg  = line.Split(';');
                        string   path = seg[0];
                        string   md5  = seg[1];
                        string   name = path.LastIndexOf('.') > 0 ? path.Substring(0, path.LastIndexOf('.')) : path;
                        name = name.Replace("{0}/", "").ToLower();
                        if (isEditor && !Application.isPlaying)
                        {
                            path = path.Replace("{0}/", "");
                        }
                        else
                        {
                            path = string.Format(path, PathUtil.GetPlatformDirectory(Application.platform));
                        }
                        if (isEditor)
                        {
                            if (Application.isPlaying == true)
                            {
                                if (path.IndexOf("Config/") == 0)
                                {
                                    path = "../Game/" + path;
                                }
                            }
                        }


                        AFileInfo fileInfo;
                        if (!assetFileInfoDict.TryGetValue(name, out fileInfo))
                        {
                            fileInfo      = new AFileInfo();
                            fileInfo.name = name;
                            assetFileInfoDict.Add(name, fileInfo);
                        }

                        fileInfo.path     = path;
                        fileInfo.md5      = md5;
                        fileInfo.loadType = loadType;
                        fileInfo.status   = AStatusType.UnCached;
                        fileInfo.bunld    = false;
                        if (seg.Length > 2)
                        {
                            fileInfo.bunld     = true;
                            fileInfo.assetName = seg[2];
                            if (seg.Length > 3)
                            {
                                fileInfo.assetBundleName = seg[3];
                            }
                            if (seg.Length > 4)
                            {
                                fileInfo.manifestName = seg[4];
                                if (!string.IsNullOrEmpty(fileInfo.manifestName))
                                {
                                    Dictionary <string, AFileInfo> manifestFileList;
                                    if (!manifestFileListDict.TryGetValue(fileInfo.manifestName, out manifestFileList))
                                    {
                                        manifestFileList = new Dictionary <string, AFileInfo>();
                                        manifestFileListDict.Add(fileInfo.manifestName, manifestFileList);
                                    }

                                    if (manifestFileList.ContainsKey(fileInfo.assetBundleName))
                                    {
                                        Debug.LogFormat("<color=red>manifestFileList[fileInfo.assetBundleName] fileInfo.assetBundleName={0} 已经存在</color>", fileInfo.assetBundleName);
                                    }

                                    manifestFileList.Add(fileInfo.assetBundleName, fileInfo);
                                }
                            }
                        }

                        if (fileInfo.assetName == "assetbundlemanifest" && !string.IsNullOrEmpty(fileInfo.manifestName))
                        {
                            manifestFileInfoDict.Add(fileInfo.manifestName, fileInfo);
                        }

                        if (string.IsNullOrEmpty(fileInfo.assetBundleName))
                        {
                            fileInfo.assetBundleName = fileInfo.name;
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 /** 加载资源 */
 public void LoadAsset(AFileInfo fileInfo, Action <string, System.Object, System.Object> callback, System.Object arg, Type type)
 {
     StartCoroutine(OnLoadAsset(fileInfo, callback, arg, type));
 }
Esempio n. 11
0
 //  加载”资源包“和他依赖的资源包
 // Load AssetBundle and its dependencies.
 void LoadAssetBundle(AFileInfo fileInfo)
 {
     bool isAlreadyProcessed = LoadAssetBundleInternal(fileInfo);
 }
Esempio n. 12
0
 void Unload(AFileInfo fileInfo)
 {
     Unload(fileInfo, false);
 }