UIKitWithResKitInit.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace QFramework
  5. {
  6. public class UIKitWithResKitInit
  7. {
  8. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  9. public static void Init()
  10. {
  11. UIKit.Config.PanelLoaderPool = new ResKitPanelLoaderPool();
  12. }
  13. }
  14. public class ResKitPanelLoaderPool : AbstractPanelLoaderPool
  15. {
  16. public class ResKitPanelLoader : IPanelLoader
  17. {
  18. private ResLoader mResLoader;
  19. public GameObject LoadPanelPrefab(PanelSearchKeys panelSearchKeys)
  20. {
  21. if (mResLoader == null)
  22. {
  23. mResLoader = ResLoader.Allocate();
  24. }
  25. if (panelSearchKeys.PanelType.IsNotNull() && panelSearchKeys.GameObjName.IsNullOrEmpty())
  26. {
  27. return mResLoader.LoadSync<GameObject>(panelSearchKeys.PanelType.Name);
  28. }
  29. if (panelSearchKeys.AssetBundleName.IsNotNullAndEmpty())
  30. {
  31. return mResLoader.LoadSync<GameObject>(panelSearchKeys.AssetBundleName, panelSearchKeys.GameObjName);
  32. }
  33. return mResLoader.LoadSync<GameObject>(panelSearchKeys.GameObjName);
  34. }
  35. public void Unload()
  36. {
  37. mResLoader.Recycle2Cache();
  38. mResLoader = null;
  39. }
  40. }
  41. protected override IPanelLoader CreatePanelLoader()
  42. {
  43. return new ResKitPanelLoader();
  44. }
  45. }
  46. }