ViewManager2.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ViewManager2
  5. {
  6. private class ViewCacheInfo
  7. {
  8. public string fullPath;
  9. public GameObject gameObject;
  10. }
  11. private static List<ViewCacheInfo> _ViewCacheInfos = new();
  12. public static void ShowView(string path)
  13. {
  14. string fullPath = "SmartBow/Prefabs/Views/" + path;
  15. _DestroyExistViews(fullPath);
  16. GameObject o = Object.Instantiate(Resources.Load<GameObject>(fullPath));
  17. ViewCacheInfo viewCacheInfo = new ViewCacheInfo();
  18. viewCacheInfo.fullPath = fullPath;
  19. viewCacheInfo.gameObject = o;
  20. _ViewCacheInfos.Add(viewCacheInfo);
  21. }
  22. public static void HideView(string path)
  23. {
  24. string fullPath = "SmartBow/Prefabs/Views/" + path;
  25. _DestroyExistViews(fullPath);
  26. }
  27. private static void _DestroyExistViews(string fullPath)
  28. {
  29. _ViewCacheInfos.FindAll(e => e.fullPath == fullPath).ForEach(e =>
  30. {
  31. if (e.gameObject) Object.Destroy(e.gameObject);
  32. });
  33. _ViewCacheInfos.RemoveAll(e => e.fullPath == fullPath);
  34. }
  35. public const string Path_SettingsView = "Home/SettingsView";
  36. }