/// <summary> /// 加载预制体 /// </summary> void LoadPrefab() { // 通过 LoadSync 同步加载资源 // 只需要传入资源名即可,不需要传入 AssetBundle 名。 //mResLoader.LoadSync<GameObject>("AssetBundleTest1") // .Instantiate(); // 通过 LoadAsync 异步加载资源 // 添加到加载队列 // 添加一个资源 mResLoader.Add2Load("AssetBundleTest1", (succeed, res) => { if (succeed) { res.Asset.As <GameObject>() .Instantiate(); } }); // 加载一个资源,不处理 mResLoader.Add2Load("AssetBundleTest1", (succeed, res) => { }); // 加载一个列表中的资源 mResLoader.Add2Load(new List <string>() { "AssetBundleTest1", "AssetBundleTest2" }); // 执行加载操作 mResLoader.LoadAsync(() => { // 可以监听所有的资源是否加载成功 "资源加载成功".LogInfo(); }); }
/// <summary> /// 异步的加载方式 /// </summary> void Async() { mResLoader.Add2Load("SceneRes"); mResLoader.LoadAsync(() => { SceneManager.LoadScene("SceneRes"); }); }
IEnumerator Start() { yield return(ResKit.InitAsync()); mResLoader.Add2Load <GameObject>("Image"); mResLoader.Add2Load <Texture2D>("WebGLTestTexture"); mResLoader.LoadAsync(() => { var imagePrefab = mResLoader.LoadSync <GameObject>("Image"); var image = imagePrefab.InstantiateWithParent(this.transform).GetComponent <Image>(); var texture2D = mResLoader.LoadSync <Texture2D>("WebGLTestTexture"); var sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f); image.sprite = sprite; }); yield return(new WaitForSeconds(3.0f)); // 申请一个 ResLoader var resLoader = ResLoader.Allocate(); // 提前加载 HelloWebGL resLoader.Add2Load <GameObject>("HelloWebGLPanel"); // 异步加载 resLoader.LoadAsync(() => { // 打开界面 UIKit.OpenPanel <HelloWebGLPanel>() .OnClosed(() => { // 关闭时卸载 resLoader resLoader.Recycle2Cache(); resLoader = null; }); }); }
// Use this for initialization private IEnumerator Start() { ResMgr.Init(); // net image mResLoader.Add2Load( "http://qframework.io/content/images/2017/07/-----2017-07-01-12-14-56.png".ToNetImageResName(), delegate(bool b, IRes res) { Log.E(b); if (b) { var texture2D = res.Asset as Texture2D; transform.Find("Image").GetComponent <Image>().sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f); } }); mResLoader.LoadAsync(); yield return(new WaitForSeconds(5.0f)); mResLoader.Recycle2Cache(); mResLoader = null; yield return(new WaitForSeconds(1.0f)); mResLoader = ResLoader.Allocate(); // local image var localImageUrl = "file://" + Application.persistentDataPath + "/Workspaces/lM1wmsLQtfzRQc6fsdEU.jpg"; mResLoader.Add2Load(localImageUrl.ToLocalImageResName(), delegate(bool b, IRes res) { Log.E(b); if (b) { var texture2D = res.Asset as Texture2D; transform.Find("Image").GetComponent <Image>().sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f); } }); mResLoader.LoadAsync(); yield return(new WaitForSeconds(5.0f)); mResLoader.Recycle2Cache(); mResLoader = null; }
public override void InitSys() { base.InitSys(); loader = ResLoader.Allocate(); loader.Add2Load(QAssetBundle.Scenelogin_unity.SCENELOGIN); loader.LoadAsync(() => { Log.I("加载场景成功"); SceneManager.LoadScene("SceneLogin"); }); // loader.LoadSync(QAssetBundle.Scenelogin_unity.SCENELOGIN); PECommon.Log("Init LoginSys..."); }
// Use this for initialization void Start() { var image = transform.Find("Image").GetComponent <Image>(); mResLoader.Add2Load <Texture2D>( "netimage:" + "http://pic.616pic.com/ys_b_img/00/44/76/IUJ3YQSjx1.jpg", (b, res) => { if (b) { var texture = res.Asset as Texture2D; var sprite = texture.CreateSprite(); image.sprite = sprite; mResLoader.AddObjectForDestroyWhenRecycle2Cache(sprite); } }); mResLoader.LoadAsync(); }
// Use this for initialization void Start() { var image = transform.Find("Image").GetComponent <Image>(); mResLoader.Add2Load <Texture2D>( "netimage:" + "https://file.liangxiegame.com/8eb58e6e-c6ac-40fe-a4a0-17b59fb6f5ed.png", (b, res) => { if (b) { var texture = res.Asset as Texture2D; var sprite = texture.CreateSprite(); image.sprite = sprite; mResLoader.AddObjectForDestroyWhenRecycle2Cache(sprite); } }); mResLoader.LoadAsync(); }