private BundleNode GetBundleNode(string bundlePath)
        {
            if (bundleNodeDic.TryGetValue(bundlePath, out var bundleNode))
            {
                if (bundleNode.IsDone)
                {
                    return(bundleNode);
                }
                else
                {
                    throw new Exception("");
                }
            }

            BundleNode mainBundleNode = bundleNodePool.Get();

            string[] dependBundlePaths = bundleDetailConfig.GetDependencies(bundlePath);
            for (int i = 0; i < dependBundlePaths.Length; i++)
            {
                BundleNode dependBundleNode = GetBundleNode(dependBundlePaths[i]);
                mainBundleNode.BindDepend(dependBundleNode);
            }

            AssetBundle bundle = LoadBundleFromFile(bundlePath);

            mainBundleNode.Bundle = bundle;

            bundleNodeDic.Add(bundlePath, mainBundleNode);

            return(mainBundleNode);
        }
        protected override void OnCreateAssetNodeAsync(AssetNode assetNode)
        {
            string     bundlePath = assetDetailConfig.GetBundleByPath(assetNode.Path);
            BundleNode bundleNode = GetAsyncBundleNode(bundlePath);

            bundleNode.RetainRef();
        }
        protected override UnityObject RequestAssetSync(string assetPath)
        {
            var        bundlePath = assetDetailConfig.GetBundleByPath(assetPath);
            BundleNode bundleNode = GetBundleNode(bundlePath);

            return(LoadAssetFromBundle(bundleNode, assetPath));
        }
        protected override void OnAsyncRequestUpdate(AsyncRequest request)
        {
            var result = request.result;

            string[] assetPaths = request.paths;
            for (int i = 0; i < assetPaths.Length; i++)
            {
                if (result.IsDoneAt(i))
                {
                    continue;
                }

                string    assetPath = assetPaths[i];
                AssetNode assetNode = assetNodeDic[assetPath];
                if (assetNode.IsLoaded())
                {
                    if (request.isInstance)
                    {
                        request.SetUObject(i, assetNode.CreateInstance());
                    }
                    else
                    {
                        request.SetUObject(i, assetNode.GetAsset());
                    }
                    assetNode.ReleaseRef();
                    continue;
                }
                else
                {
                    string     bundlePath = assetDetailConfig.GetBundleByPath(assetPath);
                    BundleNode bundleNode = bundleNodeDic[bundlePath];
                    if (bundleNode.IsDone && !assetOperationDic.ContainsKey(assetPath))
                    {
                        BundleAssetAsyncOperation assetOperation = assetOperationPool.Get();
                        assetOperation.DoInitilize(assetPath);
                        assetOperation.OnOperationComplete = OnAssetFromBundleCreated;

                        assetOperationDic.Add(assetPath, assetOperation);
                        operationLDic.Add(assetPath, assetOperation);
                    }
                    request.SetProgress(i, GetAsyncAssetProgress(assetPath));
                }
            }
            if (result.IsDone())
            {
                if (request.isInstance)
                {
                    request.state = RequestState.InstanceFinished;
                }
                else
                {
                    request.state = RequestState.LoadFinished;
                }
            }
        }
 private UnityObject LoadAssetFromBundle(BundleNode bundleNode, string assetPath)
 {
     if (bundleNode.Bundle != null)
     {
         return(bundleNode.Bundle.LoadAsset(assetPath));
     }
     else
     {
         return(null);
     }
 }
        protected override bool OnUnloadAssetsUpdate()
        {
            bool isFinished = true;
            var  keys       = bundleNodeDic.Keys;

            foreach (var key in keys)
            {
                BundleNode node = bundleNodeDic[key];
                if (!node.IsInUsing())
                {
                    isFinished = false;

                    bundleNodeDic.Remove(key);
                    bundleNodePool.Release(node);
                }
            }

            return(isFinished);
        }
        private float GetAsycBundleProgress(string bundlePath)
        {
            BundleNode bundleNode = bundleNodeDic[bundlePath];
            float      progress;

            if (bundleNode.IsDone)
            {
                progress = 1.0f;
            }
            else if (bundleOperationDic.TryGetValue(bundlePath, out var operation))
            {
                progress = operation.Progress;
            }
            else
            {
                progress = 0.0f;
            }
            return(progress);
        }
        private void TryToReleaseBundleNode(string bundlePath)
        {
            if (!bundleNodeDic.TryGetValue(bundlePath, out var bundleNode))
            {
                return;
            }
            bundleNode.ReleaseRef();
            if (!bundleNode.IsInUsing())
            {
                bundleNodeDic.Remove(bundlePath);
                bundleNodePool.Release(bundleNode);

                string[] dependBundlePaths = bundleDetailConfig.GetDependencies(bundlePath);
                foreach (var dbp in dependBundlePaths)
                {
                    BundleNode dependBundleNode = bundleNodeDic[dbp];
                    if (!dependBundleNode.IsInUsing())
                    {
                        bundleNodeDic.Remove(bundlePath);
                        bundleNodePool.Release(bundleNode);
                    }
                }
            }
        }
 internal void BindDepend(BundleNode node)
 {
     node.RetainRef();
     depends.Add(node);
 }