public static SpriteLoader Load(string path, CSpriteLoaderDelegate callback = null) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as Sprite); } return(AutoNew <SpriteLoader>(path, newCallback)); }
public static KAtlasLoader Load(string path, CAtlasLoaderDelegate callback = null) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetPacker); } return(AutoNew <KAtlasLoader>(path, newCallback)); }
public static AudioLoader Load(string url, System.Action <bool, AudioClip> callback = null) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AudioClip); } return(AutoNew <AudioLoader>(url, newCallback)); }
/// <summary> /// 统一的对象工厂 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url"></param> /// <param name="callback"></param> /// <param name="forceCreateNew"></param> /// <returns></returns> protected static T AutoNew <T>(string url, LoaderDelgate callback = null, bool forceCreateNew = false, params object[] initArgs) where T : AbstractResourceLoader, new() { if (string.IsNullOrEmpty(url)) { Log.Error("[{0}:AutoNew]url为空", typeof(T)); return(null); } Dictionary <string, AbstractResourceLoader> typesDict = ABManager.GetTypeDict(typeof(T)); AbstractResourceLoader loader; typesDict.TryGetValue(url, out loader); if (forceCreateNew || loader == null) { loader = new T(); if (!forceCreateNew) { typesDict[url] = loader; } loader.IsForceNew = forceCreateNew; loader.Init(url, initArgs); if (Application.isEditor) { KResourceLoaderDebugger.Create(typeof(T).Name, url, loader); } } else if (loader != null && loader.IsCompleted && loader.IsError) { loader.Init(url, initArgs); } else { if (loader.RefCount < 0) { //loader.IsDisposed = false; // 转死回生的可能 Log.Error("Error RefCount!"); } } loader.RefCount++; // RefCount++了,重新激活,在队列中准备清理的Loader if (ABManager.UnUsesLoaders.ContainsKey(loader)) { ABManager.UnUsesLoaders.Remove(loader); loader.Revive(); } loader.AddCallback(callback); return(loader as T); }
/// <summary> /// 统一的对象工厂 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url"></param> /// <param name="callback"></param> /// <param name="forceCreateNew"></param> /// <returns></returns> protected static T AutoNew <T>(string url, LoaderDelgate callback = null, bool forceCreateNew = false, params object[] initArgs) where T : AbstractResourceLoader, new() { Dictionary <string, AbstractResourceLoader> typesDict = GetTypeDict(typeof(T)); AbstractResourceLoader loader; if (string.IsNullOrEmpty(url)) { Debug.LogErrorFormat("[{0}:AutoNew]url为空", typeof(T)); } bool needInit = false; if (forceCreateNew || !typesDict.TryGetValue(url, out loader)) { loader = new T(); if (!forceCreateNew) { typesDict[url] = loader; } loader.IsForceNew = forceCreateNew; needInit = true; #if UNITY_EDITOR KResourceLoaderDebugger.Create(typeof(T).Name, url, loader); #endif } else { if (loader.RefCount < 0) { //loader.IsDisposed = false; // 转死回生的可能 Debug.LogErrorFormat("Error RefCount!"); } } loader.RefCount++; // RefCount++了,重新激活,在队列中准备清理的Loader if (UnUsesLoaders.ContainsKey(loader)) { UnUsesLoaders.Remove(loader); loader.Revive(); } loader.AddCallback(callback); if (needInit) { loader.Init(url, initArgs); } return(loader as T); }
public static FontLoader Load(string path, Action <bool, Font> callback = null) { LoaderDelgate realcallback = null; if (callback != null) { realcallback = (isOk, obj) => callback(isOk, obj as Font); } return(AutoNew <FontLoader>(path, realcallback)); }
public static StaticAssetLoader Load(string url, AssetFileLoader.AssetFileBridgeDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as UnityEngine.Object); } return(AutoNew <StaticAssetLoader>(url, newCallback, false, loaderMode)); }
public static KAssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as UnityEngine.Object); } return(AutoNew <KAssetFileLoader>(path, realcallback, false, loaderMode)); }
public static AssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null) { LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as Object); } return(AutoNew <AssetFileLoader>(path, realcallback, false)); }
public static SceneLoader Load(string url, System.Action <bool> callback = null, LoaderMode mode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk); } return(AutoNew <SceneLoader>(url, newCallback, false, mode)); }
public static AssetResolveLoader LoadAll(string path, string package, Type type, OnLoadAssetList onFinish = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate realcallback = null; if (onFinish != null) { realcallback = (isOk, obj) => onFinish(isOk, obj as Object[]); } return(AutoNew <AssetResolveLoader>(path, realcallback, false, loaderMode, package, type, true)); }
/// <summary> /// AssetBundle读取原字节目录 /// </summary> //private KResourceInAppPathType _inAppPathType; public static AssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew <AssetBundleLoader>(url, newCallback, false, loaderMode); return(newLoader); }
public static AssetBundleLoader Load(string url, LoaderDelgate callback = null) { url = url.ToLower(); LoaderDelgate newCallback = null; if (callback != null) { newCallback = (useUrl, obj) => callback(useUrl, obj as AssetBundle); } var newLoader = AutoNew <AssetBundleLoader>(url, newCallback); return(newLoader); }
/// <summary> /// 统一的对象工厂 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url"></param> /// <param name="callback"></param> /// <param name="forceCreateNew"></param> /// <returns></returns> protected static T AutoNew <T>(string url, LoaderDelgate callback = null, params object[] initArgs) where T : AbstractResourceLoader, new() { Dictionary <string, AbstractResourceLoader> typesDict = GetTypeDict(typeof(T)); AbstractResourceLoader loader; if (string.IsNullOrEmpty(url)) { Debug.LogErrorFormat("[{0}:AutoNew]url为空", typeof(T)); return(null); } if (!typesDict.TryGetValue(url, out loader)) //forceCreateNew || { loader = new T(); //if (!forceCreateNew) { typesDict[url] = loader; } //loader.IsForceNew = forceCreateNew; loader.Init(url, initArgs); //if (Application.isEditor) { // KResourceLoaderDebugger.Create(typeof(T).Name, url, loader); } } else { //if (loader.RefCount < 0) //{ //loader.IsDisposed = false; // 转死回生的可能 // Log.Error("Error RefCount!"); //} } //loader.RefCount++; // RefCount++了,重新激活,在队列中准备清理的Loader //if (UnUsesLoaders.ContainsKey(loader)) //{ // UnUsesLoaders.Remove(loader); // loader.Revive(); //} loader.AddCallback(callback); return(loader as T); }
public static AssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null, LoaderMode loaderMode = LoaderMode.Async) { // 添加扩展名 path = path + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt); LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as Object); } return(AutoNew <AssetFileLoader>(path, realcallback, false, loaderMode)); }
public static SpriteLoader Load(string path, CSpriteLoaderDelegate callback = null) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => { var t2d = obj as UnityEngine.Texture2D; var sp = Sprite.Create(t2d, new Rect(0, 0, t2d.width, t2d.height), new Vector2(0.5f, 0.5f)); callback(isOk, sp as Sprite); }; } return(AutoNew <SpriteLoader>(path, newCallback)); }
public static SceneLoader Load(string url, System.Action <bool> callback = null, LoaderMode mode = LoaderMode.Async) { UnloadPreScene(); LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk); } var loader = AutoNew <SceneLoader>(url, newCallback, true, mode); preSceneLoader = loader; return(preSceneLoader); }
/// <summary> /// AssetBundle读取原字节目录 /// </summary> //private KResourceInAppPathType _inAppPathType; public static AssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { #if UNITY_5 || UNITY_2017_1_OR_NEWER url = url.ToLower(); #endif LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew <AssetBundleLoader>(url, newCallback, false, loaderMode); return(newLoader); }
public static AssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null, LoaderMode loaderMode = LoaderMode.Async) { // 添加扩展名 if (!IsEditorLoadAsset) { path = path + EngineConfig.instance.ABExtName; } LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as Object); } return(AutoNew <AssetFileLoader>(path, realcallback, false, loaderMode)); }
public static AssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null, LoaderMode loaderMode = LoaderMode.Async) { // 添加扩展名 if (!KResourceModule.IsEditorLoadAsset) { path = path + AppConfig.AssetBundleExt; } LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as Object); } return(AutoNew <AssetFileLoader>(path, realcallback, false, loaderMode)); }
/// <summary> /// 在IsFinisehd后悔执行的回调 /// </summary> /// <param name="callback"></param> protected void AddCallback(LoaderDelgate callback) { if (callback != null) { if (IsCompleted) { if (ResultObject == null) { Log.Warning("Null ResultAsset {0}", Url); } callback(ResultObject != null, ResultObject); } else { _afterFinishedCallbacks.Add(callback); } } }
/// <summary> /// 在IsFinisehd后悔执行的回调 /// </summary> /// <param name="callback"></param> protected void AddCallback(LoaderDelgate callback) { if (callback != null) { if (IsCompleted) { if (ResultObject == null) { Debug.LogWarningFormat("Null ResultAsset {0}", Url); } callback(Url, ResultObject, null); } else { _afterFinishedCallbacks.Add(callback); } } }
/// <summary> /// 加载ab /// </summary> /// <param name="url">资源路径</param> /// <param name="callback">加载完成的回调</param> /// <param name="loaderMode">Async异步,sync同步</param> /// <returns></returns> public static AssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { if (!KResourceModule.IsEditorLoadAsset && !url.EndsWith(AppConfig.AssetBundleExt)) { url = url + AppConfig.AssetBundleExt; } #if UNITY_5 || UNITY_2017_1_OR_NEWER url = url.ToLower(); #endif LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew <AssetBundleLoader>(url, newCallback, false, loaderMode); return(newLoader); }
public static KSpriteAtlasLoader Load(string path, string spriteName, CKSpriteAtlasLoaderDelegate callback = null) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => { SpriteAtlas spriteAtlas = obj as SpriteAtlas; if (spriteAtlas != null) { var sp = spriteAtlas.GetSprite(spriteName); callback(isOk, sp); } else { callback(isOk, null); } }; } return(AutoNew <KSpriteAtlasLoader>(path, newCallback)); }
//public int DownloadedSize { get { return Www != null ? Www.bytesDownloaded : 0; } } /// <summary> /// Use this to directly load WWW by Callback or Coroutine, pass a full URL. /// A wrapper of Unity's WWW class. /// </summary> public static KWWWLoader Load(string url, LoaderDelgate callback = null) { var wwwLoader = AutoNew<KWWWLoader>(url, callback); return wwwLoader; }
public static AssetLoader Load(string path, LoaderDelgate callback = null, params object[] initArgs) { return(AutoNew <AssetLoader>(path, callback, initArgs)); }
//public int DownloadedSize { get { return Www != null ? Www.bytesDownloaded : 0; } } /// <summary> /// Use this to directly load WWW by Callback or Coroutine, pass a full URL. /// A wrapper of Unity's WWW class. /// </summary> public static KWWWLoader Load(string url, LoaderDelgate callback = null) { var wwwLoader = AutoNew <KWWWLoader>(url, callback); return(wwwLoader); }
public static BytesLoader Load(string path, LoaderDelgate callback = null) { var newLoader = AutoNew <BytesLoader>(path, callback); return(newLoader); }
public static AssetLoader Load(string path, LoaderDelgate callback = null) { return(AutoNew <AssetLoader>(path, callback)); }
public static SceneResolveLoader Load(string sceneName, string package = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single, LoaderDelgate onFinish = null, LoaderMode loaderMode = LoaderMode.Async) { return(AutoNew <SceneResolveLoader>(sceneName, onFinish, false, loaderMode, package, loadSceneMode)); }