Example #1
0
        public override void Initialize()
        {
            var path = Helper.GetInternalPath(name.ToLower());

            _request = AssetBundle.LoadFromFileAsync(path);
            if (_request == null)
            {
                error = name + " LoadFromFileAsync falied.";
            }
            var items = Bundles.GetBundleDependencies(name.ToLower());

            if (items != null && items.Length > 0)
            {
                for (int i = 0, I = items.Length; i < I; i++)
                {
                    var item = items[i];
                    if (Bundles.IsCyclicDependsLoaded(item))
                    {
                        Debug.LogWarning("Cyclic dependence " + name);
                    }
                    else
                    {
                        dependencies.Add(Bundles.LoadAsync(item));
                    }
                }
            }
        }
Example #2
0
        public override void Initialize()
        {
            var path = Helper.GetDataPath(name.ToLower());

            if (Bundles.IsInternal(name))
            {
                path = "file:///" + Helper.GetInternalPath(name);
            }
            _request = UnityWebRequestAssetBundle.GetAssetBundle(path, Bundles.GetHash128(name), 0);
            _request.SendWebRequest();
            if (_request == null)
            {
                error = name + " LoadFromFileAsync falied.";
            }
            var items = Bundles.GetBundleDependencies(name.ToLower());

            if (items != null && items.Length > 0)
            {
                for (int i = 0, I = items.Length; i < I; i++)
                {
                    var item = items[i];
                    if (Bundles.IsCyclicDependsLoaded(item))
                    {
                        Debug.LogWarning("Cyclic dependence " + name);
                    }
                    else
                    {
                        dependencies.Add(Bundles.LoadAsync(item));
                    }
                }
            }
        }
Example #3
0
        public override void Initialize()
        {
            var path = Helper.GetInternalPath(name);

            _assetBundle = AssetBundle.LoadFromFile(path);

            if (_assetBundle == null)
            {
                error = name + " LoadFromFile failed.";
            }
            var items = Bundles.GetBundleDependencies(name.ToLower());

            if (items != null && items.Length > 0)
            {
                for (int i = 0, I = items.Length; i < I; i++)
                {
                    var item = items[i];
                    if (Bundles.IsCyclicDependsLoaded(item))
                    {
#if UNITY_EDITOR
                        Debug.LogWarning("Cyclic dependence " + name);
#endif
                    }
                    else
                    {
                        dependencies.Add(Bundles.Load(item));
                    }
                }
            }
        }
Example #4
0
 public override void Initialize()
 {
     if (string.IsNullOrEmpty(bundlePath))
     {
         Debug.LogError("bundlePath is Null <= " + assetPath);
         return;
     }
     request = Bundles.Load(bundlePath, true);
     asset   = request?.LoadAsset(assetPath, assetType);
 }
Example #5
0
        static IEnumerator UpgradeAssets(Action <float, float> dealcb, Action <float, float> overcb)
        {
            long  allsize = 0;
            float cursize = 0;

#if UNITY_EDITOR
            if (LoadType != AssetType.LocalAsset)
#endif
            {
                var bundles = Bundles.GetChangedList();
                foreach (var b in bundles)
                {
                    allsize += b.Value.bundleSize;
                }
                if (allsize > 0)
                {
                    var nbundles = new Dictionary <string, float>();

                    int  Mx      = 8;
                    int  count   = Mx;
                    long curTime = System.DateTime.UtcNow.Ticks;
                    foreach (var b in bundles)
                    {
                        count--;
                        AB.Assets.ObtainNetwork(b.Value, (bundleName, bundleProgress, bundleOver) =>
                        {
                            if (bundleOver)
                            {
                                count++;
                            }
                            bundleProgress       = bundleProgress < 0 ? 0 : bundleProgress;
                            nbundles[bundleName] = bundles[bundleName].bundleSize * bundleProgress;
                            cursize = 0;
                            foreach (var nb in nbundles)
                            {
                                cursize += nb.Value;
                            }

                            dealcb?.Invoke(cursize, allsize);
                        });
                        while (count <= 0)
                        {
                            yield return(new WaitForEndOfFrame());
                        }
                    }
                    while (count < Mx)
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                    Debug.Log("Upgrade Assets UseTime:" + (System.DateTime.UtcNow.Ticks - curTime));
                }
            }
            overcb?.Invoke(cursize, allsize);
        }
Example #6
0
 public override void Initialize()
 {
     loadInited = true;
     if (string.IsNullOrEmpty(bundlePath))
     {
         loadState = 2;
         Debug.LogError("bundlePath is Null <= " + assetPath);
         return;
     }
     request = Bundles.LoadAsync(bundlePath, true);
 }
Example #7
0
        static Asset LoadInternal(string path, System.Type type, bool asyncMode)
        {
            path = path.ToLower();
            Asset asset = assets.Find(obj => { return(obj.assetPath == path); });

            if (asset == null)
            {
                var bundleName = Bundles.GetBundleName(path);
#if UNITY_EDITOR
                if (LoadType == AssetType.LocalAsset)
                {
                    asset = new Asset(path, bundleName?.bundleName, type);
                }
                else
#endif
                if (true)
                {
                    if (asyncMode)
                    {
                        asset = new BundleAssetAsync(path, bundleName?.bundleName, type);
                    }
                    else
                    {
                        asset = new BundleAsset(path, bundleName?.bundleName, type);
                    }
                }
                //处理正在卸载的情况
                if (AsyncOperationUnloadUnusedAssets != null)
                {
                    var tick = DateTime.Now.Ticks;
                    Debug.Log("Wait UnloadUnusedAssets Begin");
                    if (asyncMode)
                    {
                        Instance.StartCoroutine(Instance.AssetInitialize(asset));
                    }
                    else
                    {
                        while (!AsyncOperationUnloadUnusedAssets.isDone)
                        {
                            Thread.Yield();
                        }
                    }
                    Debug.Log("Wait UnloadUnusedAssets End use :" + (DateTime.Now.Ticks - tick));
                }
                else
                {
                    asset.Initialize();
                }
                assets.Add(asset);
            }
            asset.Load();
            return(asset);
        }
Example #8
0
        public static IEnumerator Initialize()
        {
#if UNITY_EDITOR
            var ins = Instance;
            if (LoadType == AssetType.LocalAsset)
            {
                Bundles.InitializeForEditor();
            }
            else
#endif
            yield return(InitializeBundle());
        }
Example #9
0
        public virtual void Initialize()
        {
            var path = Helper.GetDataPath(name.ToLower());
            //使用了Caching的资源 AssetBundle.LoadFromFile 找不到路径,这里直接阻塞等待加载完成,
            //按照官方文档上说的,对已经Cache的资源UnityWebRequest.GetAssetBundle 和 AssetBundle.LoadFromFile 功能一样,都会立刻返回
            var _request = UnityWebRequestAssetBundle.GetAssetBundle(path, Bundles.GetHash128(name), 0);

            _request.SendWebRequest();
            while (!_request.isDone)
            {
                Thread.Yield();
            }
            _assetBundle = DownloadHandlerAssetBundle.GetContent(_request);

            _request.Dispose();

            if (_assetBundle == null)
            {
                error = name + " LoadFromFile failed.";
            }
            var items = Bundles.GetBundleDependencies(name.ToLower());

            if (items != null && items.Length > 0)
            {
                for (int i = 0, I = items.Length; i < I; i++)
                {
                    var item = items [i];
                    if (Bundles.IsCyclicDependsLoaded(item))
                    {
#if UNITY_EDITOR
                        Debug.LogWarning("Cyclic dependence " + name);
#endif
                    }
                    else
                    {
                        dependencies.Add(Bundles.Load(item));
                    }
                }
            }
        }
Example #10
0
        void Update()
        {
            bool loading = false;

            for (int i = 0; i < assets.Count; i++)
            {
                var asset = assets[i];
                if (asset.isDone)
                {
                    asset.Update();
                    if (asset.references <= 0)
                    {
                        asset.Dispose();
                        asset = null;
                        assets.RemoveAt(i);
                        i--;
                    }
                }
                else
                {
                    loading = true;
                }
            }

            if (!loading)
            {
                Bundles.Update();
                times += Time.deltaTime;
                if (times > 120)
                {
                    times = 0;
                    if (AsyncOperationUnloadUnusedAssets == null)
                    {
                        StartCoroutine(UnloadUnusedAssets());
                    }
                }
            }
        }
Example #11
0
 static IEnumerator InitializeBundle()
 {
     yield return(Bundles.Initialize());
 }
Example #12
0
 public static bool Exists(string path)
 {
     path = path.ToLower();
     return(Bundles.GetBundleName(path) != null);
 }