Exemple #1
0
        private void Update()
        {
            for (var i = 0; i < _assets.Count; i++)
            {
                var item = _assets [i];
                if (item.Update() || !item.IsUnused())
                {
                    continue;
                }
                _unusedAssets.Add(item);
                _assets.RemoveAt(i);
                i--;
            }

            for (var i = 0; i < _unusedAssets.Count; i++)
            {
                var item = _unusedAssets [i];
                item.Unload();
                Log("Unload->" + item.name);
            }

            _unusedAssets.Clear();

            Bundles.Update();
        }
Exemple #2
0
 private static void InitBundles(Action onSuccess, Action <string> onError)
 {
     Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL;
     Bundles.Initialize(() => {
         var asset        = LoadAsync(Assets.AssetsManifestAsset, typeof(AssetManifest));
         asset.completed += obj => {
             var manifest = obj.asset as AssetManifest;
             if (manifest == null)
             {
                 if (onError != null)
                 {
                     onError.Invoke("manifest == null");
                 }
                 return;
             }
             downloadURL            = Path.Combine(manifest.downloadURL, platform) + Path.DirectorySeparatorChar;
             Bundles.activeVariants = manifest.activeVariants;
             _bundles = manifest.bundles;
             var dirs = manifest.dirs;
             _bundleAssets.Clear();
             for (int i = 0, max = manifest.assets.Length; i < max; i++)
             {
                 var item = manifest.assets [i];
                 _bundleAssets [string.Format("{0}/{1}", dirs [item.dir], item.name)] = item.bundle;
             }
             if (onSuccess != null)
             {
                 onSuccess.Invoke();
             }
             obj.Release();
         };
     }, onError);
 }
Exemple #3
0
        internal override void Load()
        {
            bundle = Bundles.Load(assetBundleName);
            var assetName = Path.GetFileName(name);

            asset = bundle.assetBundle.LoadAsset(assetName, assetType);
        }
Exemple #4
0
 internal override void Load()
 {
     if (!string.IsNullOrEmpty(assetBundleName))
     {
         bundle    = Bundles.LoadAsync(assetBundleName);
         loadState = LoadState.LoadAssetBundle;
     }
     else
     {
         _request  = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
         loadState = LoadState.LoadAsset;
     }
 }
Exemple #5
0
 internal override void Load()
 {
     if (!string.IsNullOrEmpty(assetBundleName))
     {
         bundle = Bundles.Load(assetBundleName);
         if (bundle != null)
         {
             SceneManager.LoadScene(sceneName, loadSceneMode);
         }
     }
     else
     {
         SceneManager.LoadScene(sceneName, loadSceneMode);
     }
 }
Exemple #6
0
        public static string[] GetAllDependencies(string path)
        {
            string assetBundleName;

            return(GetAssetBundleName(path, out assetBundleName) ? Bundles.GetAllDependencies(assetBundleName) : null);
        }
Exemple #7
0
        public static void Initialize(Action onSuccess, Action <string> onError)
        {
            var instance = FindObjectOfType <Assets>();

            if (instance == null)
            {
                instance = new GameObject("Assets").AddComponent <Assets>();
                DontDestroyOnLoad(instance.gameObject);
            }

            if (string.IsNullOrEmpty(Utility.dataPath))
            {
                Utility.dataPath = Application.streamingAssetsPath;
            }

            Log(string.Format("Init->assetBundleMode {0} | dataPath {1}", Utility.assetBundleMode, Utility.dataPath));

            if (Utility.assetBundleMode)
            {
                updatePath = Utility.updatePath;
                var platform = Utility.GetPlatform();
                var path     = Path.Combine(Utility.dataPath, Path.Combine(Utility.AssetBundles, platform)) +
                               Path.DirectorySeparatorChar;
                Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL;
                Bundles.Initialize(path, platform, () =>
                {
                    var asset        = LoadAsync(Utility.AssetsManifestAsset, typeof(AssetsManifest));
                    asset.completed += obj =>
                    {
                        var manifest = obj.asset as AssetsManifest;
                        if (manifest == null)
                        {
                            if (onError != null)
                            {
                                onError("manifest == null");
                            }
                            return;
                        }

                        if (string.IsNullOrEmpty(Utility.downloadURL))
                        {
                            Utility.downloadURL = manifest.downloadURL;
                        }
                        Bundles.activeVariants = manifest.activeVariants;
                        _bundles      = manifest.bundles;
                        var dirs      = manifest.dirs;
                        _bundleAssets = new Dictionary <string, int>(manifest.assets.Length);
                        for (int i = 0, max = manifest.assets.Length; i < max; i++)
                        {
                            var item = manifest.assets[i];
                            _bundleAssets[string.Format("{0}/{1}", dirs[item.dir], item.name)] = item.bundle;
                        }

                        if (onSuccess != null)
                        {
                            onSuccess();
                        }
                        obj.Release();
                    };
                }, onError);
            }
            else
            {
                if (onSuccess != null)
                {
                    onSuccess();
                }
            }
        }
Exemple #8
0
 internal override void Load()
 {
     bundle    = Bundles.LoadAsync(assetBundleName);
     loadState = LoadState.LoadAssetBundle;
 }