Exemple #1
0
        protected static void Set <TargetComponent_AssetObjectType>(TargetComponent component, AssetCat assetCat,
                                                                    string assetPath) where TargetComponent_AssetObjectType : AutoAssetRelease <TargetComponent, AssetObjectType>
        {
            if (component == null || assetCat == null)
            {
                return;
            }

            var ai = component.GetComponent <TargetComponent_AssetObjectType>();

            if (ai != null)
            {
                ai.ReleaseAll();
            }
            else
            {
                ai = component.gameObject.AddComponent <TargetComponent_AssetObjectType>();
            }

            ai.SetCurAssetCat(assetCat, assetPath);
            assetCat.AddRefCount();
        }
        public BaseAssetAsyncLoader LoadAssetAsync(string assetPath, Action <AssetCat> onLoadSuccessCallback = null,
                                                   Action <AssetCat> onLoadFailCallback = null, Action <AssetCat> onLoadDoneCallback = null,
                                                   object callbackCause = null)
        {
            AssetCat assetCat;

            if (Application.isEditor && EditorModeConst.IsEditorMode ||
                assetPath.Contains(FilePathConst.ResourcesFlag)
                )
            {
                assetCat = __GetOrAddAssetCat(assetPath);
                onLoadSuccessCallback?.Invoke(assetCat);
                onLoadDoneCallback?.Invoke(assetCat);
                return(new EditorAssetAsyncLoader(assetCat));
            }

            var assetBundleName = assetPathMap.GetAssetBundleName(assetPath);

            if (assetBundleName == null)
            {
                LogCat.error(string.Format("{0}没有设置成ab包", assetPath));
            }

            if (assetCatDict.ContainsKey(assetPath))
            {
                assetCat = GetAssetCat(assetPath);
                //已经加载成功
                if (assetCat.IsLoadSuccess())
                {
                    onLoadSuccessCallback?.Invoke(assetCat);
                    onLoadDoneCallback?.Invoke(assetCat);
                    return(null);
                }

                //加载中
                assetCat.AddOnLoadSuccessCallback(onLoadSuccessCallback, callbackCause);
                assetCat.AddOnLoadFailCallback(onLoadFailCallback, callbackCause);
                assetCat.AddOnLoadDoneCallback(onLoadDoneCallback, callbackCause);
                return(assetAsyncloaderProcessingList.Find(assetAsyncloader =>
                                                           assetAsyncloader.assetCat.assetPath.Equals(assetPath)));
            }

            //没有加载
            var assetAsyncLoader = PoolCatManagerUtil.Spawn <AssetAsyncLoader>();

            assetCat = new AssetCat(assetPath);
            __AddAssetCat(assetPath, assetCat);
            //添加对assetAsyncLoader的引用
            assetCat.AddRefCount();
            assetCat.AddOnLoadSuccessCallback(onLoadSuccessCallback, callbackCause);
            assetCat.AddOnLoadFailCallback(onLoadFailCallback, callbackCause);
            assetCat.AddOnLoadDoneCallback(onLoadDoneCallback, callbackCause);

            var assetBundleLoader = __LoadAssetBundleAsync(assetBundleName);

            assetAsyncLoader.Init(assetCat, assetBundleLoader);
            //asset拥有对assetBundle的引用
            var assetBundleCat = assetBundleLoader.assetBundleCat;

            assetBundleCat.AddRefCount();

            assetCat.assetBundleCat = assetBundleCat;

            assetAsyncloaderProcessingList.Add(assetAsyncLoader);
            return(assetAsyncLoader);
        }
Exemple #3
0
 public ResLoadData(AssetCat assetCat)
 {
     this.assetCat = assetCat;
     assetCat.AddRefCount();
 }
Exemple #4
0
		/// <summary>
		///   只能通过这个方法添加
		/// </summary>
		/// <param name="go"></param>
		/// <param name="assetCat"></param>
		public static void Add(GameObject go, AssetCat assetCat)
		{
			assetCat.AddRefCount();
			var autoAssetDestroy = go.AddComponent<AutoAssetDestroy>();
			autoAssetDestroy.assetCat = assetCat;
		}