ResKit 模块简介:

加载 Resources 目录下的资源

  1. // allocate a loader when initialize a panel or a monobehavour
  2. var loader = ResLoader.Allocate();
  3.  
  4. // load someth in a panel or a monobehaviour
  5. var smobjPrefab = loader.LoadSync<GameObject>("Resources/smobj");
  6.  
  7. var bgTexture = loader.LoadSync<Texture2D>("Resources/Bg");
  8.  
  9. var gameObjPrefab = loader.LoadSync("Resources/gameObj") as GameObject;
  10.  
  11. // resycle this panel/monobehaivour loaded res when destroyed
  12. loader.Recycle2Cache();
  13. loader = null;

加载网络资源

加载 AssetBundle 资源

准备

  • 鼠标右键某个资源 Assets/ResKit/Mark AssetBundle
  • Command/Ctrl + Shift + R 弹出资源面板,点击 build

加载代码

  1. // init res mgr before load asset bundle
  2. ResMgr.Init();
  3.  
  4. // allocate a loader when initialize a panel or a monobehavour
  5. var loader = ResLoader.Allocate<ResLoader>();
  6.  
  7. // load someth in a panel or a monobehaviour
  8. var smObjPrefab = loader.LoadSync<GameObject>("smObj");
  9.  
  10. var bgTexture = loader.LoadSync<Texture2D>("Bg");
  11.  
  12. var logoTexture = loader.LoadSync<Texture2D>("hometextures","logo");
  13.  
  14. // resycle this panel/monobehaivour loaded res when destroyed
  15. loader.Recycle2Cache();
  16.  
  17. loader = null;