コード例 #1
0
 public void Dispose()
 {
     curState  = State.Prepare;
     assetName = null;
     abRef     = null;
     if (dependRefList != null)
     {
         dependRefList.Clear();
         dependRefList = null;
     }
     assetLoadCompleteCall = null;
 }
コード例 #2
0
        private void OnUnDependenciesBundle(string[] abs, string name)
        {
            if (abs == null)
            {
                return;
            }

            for (int i = 0; i < abs.Length; i++)
            {
                AssetBundleRef dependbundle = bundlesDic[abs[i]];
                dependbundle.ReduceDepCount(name);
            }
        }
コード例 #3
0
        private void CollectDepend(AssetBundleRef abr, out List <AssetBundleRef> abList)
        {
            if (abr.dependencies == null || abr.dependencies.Length == 0)
            {
                abList = null;
                return;
            }
            else
            {
                abList = new List <AssetBundleRef>();
            }

            for (int i = 0; i < abr.dependencies.Length; i++)
            {
                AssetBundleRef dependAB = bundlesDic[abr.dependencies[i]];
                if (dependAB.assetBundle == null)
                {
                    abList.Add(dependAB);
                }
            }
        }
コード例 #4
0
        public void GetAssetAsync(string bundleName, string assetName, Callback <UObject> callback)
        {
            if (!bundlesDic.ContainsKey(bundleName))
            {
                DebugUtils.LogError(DebugUtils.Type.AssetBundle, string.Format("AssetBundle \"{0}\" for this platform not found", bundleName));
                if (callback != null)
                {
                    callback(null);
                }
                return;
            }
            AssetBundleRef assetBundleRef = bundlesDic[bundleName];

            LoadingAssetBundleData loadData = new LoadingAssetBundleData();

            loadData.assetName = assetName;
            loadData.abRef     = assetBundleRef;
            CollectDepend(assetBundleRef, out loadData.dependRefList);
            loadData.assetLoadCompleteCall = callback;
            loadingBundleQueue.Enqueue(loadData);

            DebugUtils.Log(DebugUtils.Type.AssetBundle, string.Format("Prepare load bundle data \"{0}\" ,assetName is \"{1}\"", loadData.abRef.bundleName, loadData.assetName));
        }
コード例 #5
0
        public T GetAsset <T>(string bundleName, string assetName) where T : UnityEngine.Object
        {
            if (!bundlesDic.ContainsKey(bundleName))
            {
                DebugUtils.LogError(DebugUtils.Type.AssetBundle, string.Format("AssetBundle {0} for this platform not found", bundleName));
                return(null);
            }

            AssetBundleRef assetBundleRef = bundlesDic[bundleName];

            List <AssetBundleRef> dependbundleList = null;

            CollectDepend(assetBundleRef, out dependbundleList);

            int length = dependbundleList == null ? 0 : dependbundleList.Count;

            for (int i = 0; i < length; i++)
            {
                AssetBundleRef dependbundle = dependbundleList[i];
                dependbundle.AddIncreaseDep(bundleName);
                if (dependbundle.assetBundle == null)
                {
                    DebugUtils.Log(DebugUtils.Type.AssetBundle, "Start sync loading depend bundle : " + dependbundle.bundleName);
                    string dependBundlePath = assetPath + CommonUtil.EncodingToMd5(dependbundleList[i].bundleName);
                    dependbundle.assetBundle = AssetBundle.LoadFromFile(dependBundlePath);
                    if (dependbundle.assetBundle == null)
                    {
                        DebugUtils.LogError(DebugUtils.Type.AssetBundle, string.Format("AssetBundle \"{0}\" for this platform not found, path : {1}", bundleName, dependBundlePath));
                    }
                    else
                    {
                        DebugUtils.Log(DebugUtils.Type.AssetBundle, "Sync load depend bundle done, name is:" + dependbundle.bundleName);
                    }
#if UNITY_EDITOR
                    RestAssetShader(dependbundle.assetBundle.LoadAllAssets());
#endif
                }
            }

            string bundlePath = assetPath + CommonUtil.EncodingToMd5(bundleName);
            if (assetBundleRef.assetBundle == null)
            {
                DebugUtils.Log(DebugUtils.Type.AssetBundle, "Start sync loading bundle : " + bundleName);
                assetBundleRef.assetBundle = AssetBundle.LoadFromFile(bundlePath);
                DebugUtils.Log(DebugUtils.Type.AssetBundle, "Sync load depend bundle done, name is:" + bundleName);
            }

            T asset = null;

            if (assetBundleRef.assetBundle == null)
            {
                DebugUtils.LogError(DebugUtils.Type.AssetBundle, string.Format("AssetBundle \"{0}\" for this platform not found, path : {1}", bundleName, bundlePath));
            }
            else
            {
                asset = assetBundleRef.assetBundle.LoadAsset <T>(assetName);
                if (asset == null)
                {
                    DebugUtils.LogError(DebugUtils.Type.AssetBundle, string.Format("AssetBundle \"{0}\" don't contain \"{1}\" resources, type:{2}", bundleName, assetName, typeof(T)));
                }
                else
                {
#if UNITY_EDITOR
                    RestAssetShader(new UObject[] { asset });
#endif
                    assetBundleRef.AddRef(assetName);
                }
            }

            return(asset);
        }