Ejemplo n.º 1
0
        static bool InitializeBundle()
        {
            string relativePath = Path.Combine(Utility.AssetBundlesOutputPath, Utility.GetPlatformName());
            var    url          =
#if UNITY_EDITOR
                relativePath + "/";
#else
                Path.Combine(Application.streamingAssetsPath, relativePath) + "/";
#endif
            if (Bundles.Initialize(url))
            {
                var bundle = Bundles.Load("manifest");
                if (bundle != null)
                {
                    var asset = bundle.LoadAsset <TextAsset>("Manifest.txt");
                    if (asset != null)
                    {
                        using (var reader = new StringReader(asset.text))
                        {
                            manifest.Load(reader);
                            reader.Close();
                        }
                        bundle.Release();
                        Resources.UnloadAsset(asset);
                        asset = null;
                    }
                    return(true);
                }
                throw new FileNotFoundException("assets manifest not exist.");
            }
            throw new FileNotFoundException("bundle manifest not exist.");
        }
Ejemplo n.º 2
0
        void InitializeBundleAsync(System.Action onComplete)
        {
            string relativePath = Path.Combine(Utility.AssetBundlesOutputPath, Utility.GetPlatformName());
            var    url          =
#if UNITY_EDITOR
                relativePath + "/";
#else
                Path.Combine(Application.streamingAssetsPath, relativePath) + "/";
#endif

            StartCoroutine(Bundles.InitializeAsync(url, bundle => {
                if (bundle != null)
                {
                    var asset = bundle.LoadAsset <TextAsset>("Manifest.txt");
                    if (asset != null)
                    {
                        using (var reader = new StringReader(asset.text)) {
                            manifest.Load(reader);
                            reader.Close();
                        }
                        bundle.Release();
                        Resources.UnloadAsset(asset);
                        asset = null;
                    }
                }

                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
            }));
        }
Ejemplo n.º 3
0
        void Update()
        {
            bool removed = false;

            for (int i = 0; i < assets.Count; i++)
            {
                var asset = assets[i];
                if (!asset.Update() && asset.references <= 0)
                {
                    asset.Unload();
                    asset = null;
                    assets.RemoveAt(i);
                    i--;
                    removed = true;
                }
            }

            if (removed)
            {
                if (gc != null)
                {
                    StopCoroutine(gc);
                }
                gc = GC();
                StartCoroutine(gc);
            }

            Bundles.Update();
        }
Ejemplo n.º 4
0
 protected virtual void OnLoad(bool loadDependencies)
 {
     _assetBundle = AssetBundle.LoadFromFile(Bundles.GetDataPath(name) + name);
     if (_assetBundle == null)
     {
         error = name + " LoadFromFile failed.";
     }
 }
Ejemplo n.º 5
0
 protected override void OnInit(bool loadDependencies)
 {
     _request = AssetBundle.LoadFromFileAsync(Bundles.GetDataPath(name) + name);
     if (_request == null)
     {
         error = name + " LoadFromFileAsync falied.";
     }
 }
Ejemplo n.º 6
0
        public void Load(AssetLoadInfo[] assets, Loader[] customLoaders, Action <float> updateProgress, Action completed)
        {
            loaders.Clear();

            if (assets == null || assets.Length == 0)
            {
                List <string> bundles = new List <string> ();
                for (int i = 0, I = assets.Length; i < I; i++)
                {
                    var bundleName      = Assets.GetBundleName(assets [i].path);
                    var allDependencies = Bundles.GetAllDependencies(bundleName);
                    for (int j = 0, J = allDependencies.Length; j < J; j++)
                    {
                        var item = allDependencies [j];
                        if (!bundles.Contains(item))
                        {
                            bundles.Add(item);
                        }
                    }
                }
                loaders.AddRange(Array.ConvertAll <string, BundleLoader> (bundles.ToArray(), input => {
                    return(new BundleLoader()
                    {
                        bundleName = input
                    });
                }));
                bundles.Clear();
                bundles = null;

                loaders.AddRange(Array.ConvertAll <AssetLoadInfo, AssetLoader> (assets, delegate(AssetLoadInfo input) {
                    return(new AssetLoader()
                    {
                        assetPath = input.path,
                        assetType = input.type,
                        onLoad = OnLoad,
                        onUnload = OnUnload,
                    });
                }));
            }

            if (customLoaders != null && customLoaders.Length > 0)
            {
                loaders.AddRange(customLoaders);
            }

            progress = 0;

            onCompleted      = completed;
            onUpdateProgress = updateProgress;

            Cache(kCurrentCacheName);
        }
Ejemplo n.º 7
0
 protected override void OnLoad()
 {
     request = Bundles.Load(Assets.GetBundleName(assetPath));
     if (Assets.IsTjFrame)
     {
         asset = request.LoadAsset(assetPath, assetType);
     }
     else
     {
         asset = request.LoadAsset(Assets.GetAssetName(assetPath), assetType);
     }
     //   asset = request.LoadAsset(Assets.GetAssetName(assetPath), assetType);
 }
Ejemplo n.º 8
0
        static Bundle LoadInternal(string assetBundleName, bool isLoadingAssetBundleManifest, bool asyncRequest)
        {
            if (!isLoadingAssetBundleManifest)
            {
                if (manifest == null)
                {
                    Logger.L(LogType.Error, "Bundles", "Please initialize AssetBundleManifest by calling Bundles.Initialize()");
                    return(null);
                }
                assetBundleName = RemapVariantName(assetBundleName);
            }

            var    url    = Bundles.GetDataPath(assetBundleName) + assetBundleName;
            Bundle bundle = bundles.Find(obj => {
                return(obj.name == assetBundleName);
            });

            var hash = isLoadingAssetBundleManifest ? new Hash128(1, 0, 0, 0) : manifest.GetAssetBundleHash(assetBundleName);

            if (bundle == null)
            {
                if (url.StartsWith("http://") ||
                    url.StartsWith("https://") ||
                    url.StartsWith("file://") ||
                    url.StartsWith("ftp://"))
                {
                    bundle = new BundleWWW(url, hash);
                }
                else
                {
                    if (asyncRequest)
                    {
                        bundle = new BundleAsync(url, hash);
                    }
                    else
                    {
                        bundle = new Bundle(url, hash);
                    }
                }
                bundle.name = assetBundleName;
                bundles.Add(bundle);
                bundle.Load();
                if (!isLoadingAssetBundleManifest)
                {
                    LoadDependencies(bundle, assetBundleName, asyncRequest);
                }
            }
            bundle.Retain();
            return(bundle);
        }
Ejemplo n.º 9
0
        private void Update()
        {
            for (int i = 0; i < assets.Count; i++)
            {
                var asset = assets[i];
                if (asset.isDone && asset.references <= 0)
                {
                    asset.Dispose();
                    asset = null;
                    assets.RemoveAt(i);
                    i--;
                }
            }

            Bundles.Update();
        }
Ejemplo n.º 10
0
 internal void Load(bool loadDependencies)
 {
     I("Load " + name);
     OnLoad(loadDependencies);
     if (loadDependencies)
     {
         var items = Bundles.manifest.GetAllDependencies(name);
         if (items != null && items.Length > 0)
         {
             for (int i = 0, max = items.Length; i < max; i++)
             {
                 var item = items[i];
                 dependencies.Add(this is BundleAsync ? Bundles.LoadAsync(item) : Bundles.Load(item));
             }
         }
     }
 }
Ejemplo n.º 11
0
 protected virtual void OnInit(bool loadDependencies)
 {
     _assetBundle = AssetBundle.LoadFromFile(Bundles.GetDataPath(name) + name);
     if (_assetBundle == null)
     {
         error = name + " LoadFromFile failed.";
     }
     if (loadDependencies)
     {
         var items = Bundles.manifest.GetAllDependencies(name);
         if (items != null && items.Length > 0)
         {
             for (int i = 0, I = items.Length; i < I; i++)
             {
                 var item = items [i];
                 dependencies.Add(Bundles.Load(item));
             }
         }
     }
 }
Ejemplo n.º 12
0
 protected override void OnInit()
 {
     request = Bundles.LoadAsync(Assets.GetBundleName(assetPath));
 }
Ejemplo n.º 13
0
 protected override void OnInit()
 {
     request = Bundles.Load(Assets.GetBundleName(assetPath));
     asset   = request.LoadAsset(Assets.GetAssetName(assetPath), assetType);
 }
Ejemplo n.º 14
0
 public void Load()
 {
     bundle = Bundles.Load(bundleName);
 }
Ejemplo n.º 15
0
        static bool InitializeBundle()
        {
            string relativePath = Path.Combine(Settings.AssetBundlesOutputPath, Utility.GetPlatformName());
            var    url          = "";

#if UNITY_EDITOR
            if (Settings.ActiveBundleMode && Settings.ActiveDownloadMode)
            {
                url = Settings.AssetBunldesDownloadPath + "/";
            }
            else
            {
                url = relativePath + "/";
            }
#else
            if (Settings.ActiveDownloadMode)
            {
                url = Settings.AssetBunldesDownloadPath + "/";
            }
            else
            {
                url = Path.Combine(Application.streamingAssetsPath, relativePath) + "/";
            }
#endif
            if (Bundles.Initialize(url))
            {
                if (Settings.ActiveDownloadMode)
                {
                    string xManifestPath    = PatchManager.instance.localXManifestPath;
                    string xManifestContent = File.ReadAllText(xManifestPath);
                    if (xManifestContent.Length > 0)
                    {
                        using (var reader = new StringReader(xManifestContent)) {
                            manifest.Load(reader);
                            reader.Close();
                        }
                        return(true);
                    }
                }
                else
                {
                    var bundle = Bundles.Load("manifest");
                    if (bundle != null)
                    {
                        var asset = bundle.LoadAsset <TextAsset> ("Manifest.txt");
                        if (asset != null)
                        {
                            using (var reader = new StringReader(asset.text)) {
                                manifest.Load(reader);
                                reader.Close();
                            }
                            bundle.Release();
                            Resources.UnloadAsset(asset);
                            asset = null;
                        }
                        return(true);
                    }
                }
                throw new FileNotFoundException("assets manifest not exist.");
            }
            throw new FileNotFoundException("bundle manifest not exist.");
        }
Ejemplo n.º 16
0
        // 检查并下载网络资源
        public void CheckAndDownloadResource(List <string> assetPath, DownloadManager.DownloadFinishDelegate downloadAllOverCallBack)
        {
#if UNITY_EDITOR
            if (!Settings.ActiveBundleMode)
            {
                OnAllDownloadOver();
                if (downloadAllOverCallBack != null)
                {
                    downloadAllOverCallBack();
                }
                return;
            }
#endif
            if (downlodingCount != 0)
            {
                Debug.LogError("已经有下载队列");
                return;
            }
            // 检查所有
            HashSet <string> toDownload = new HashSet <string> ();
            foreach (string _path in assetPath)
            {
                Debug.Log("_path:" +
                          _path);
                string           realPath               = Assets.GetBundleName(_path);
                var              allDependencies        = Bundles.GetAllDependencies(realPath);
                HashSet <string> pathIncludeDependences = new HashSet <string> ();
                pathIncludeDependences.Add(realPath);
                foreach (string dependence in allDependencies)
                {
                    pathIncludeDependences.Add(dependence);
                }
                foreach (string __path in pathIncludeDependences)
                {
                    int _fileStatus;
                    if (!filesStatus.TryGetValue(__path, out _fileStatus))
                    {
                        filesStatus.Add(__path, FILE_STATUS_UNKOWN);
                        toDownload.Add(__path);
                    }
                    else if (_fileStatus == FILE_STATUS_UNKOWN || _fileStatus == FILE_NOT_EXIST)
                    {
                        toDownload.Add(__path);
                    }
                }
            }
            if (toDownload.Count == 0)
            {
                OnAllDownloadOver();
                if (downloadAllOverCallBack != null)
                {
                    downloadAllOverCallBack();
                }
            }
            else
            {
                DownloadManager dm = DownloadManager.instance;
                dm.OnError  += OnDownloadErr;
                dm.OnFinish += OnAllDownloadOver;
                if (downloadAllOverCallBack != null)
                {
                    curDownloadAllOverCallback = downloadAllOverCallBack;
                    dm.OnFinish += curDownloadAllOverCallback;
                }
                foreach (string realPath in toDownload)
                {
                    string _path = Path.Combine(resUrlRoot, realPath);
                    Debug.Log("下载文件:" + _path);
                    dm.Push(new DownloadManager.Request(_path, OnFileDownloadOver, realPath));
                }
                dm.Excute();
            }
        }