| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ViewManager2
- {
- private class ViewCacheInfo
- {
- public string fullPath;
- public GameObject gameObject;
- }
- private static List<ViewCacheInfo> _ViewCacheInfos = new();
- public static void ShowView(string path)
- {
- string fullPath = "SmartBow/Prefabs/Views/" + path;
- _DestroyExistViews(fullPath);
- GameObject o = Object.Instantiate(Resources.Load<GameObject>(fullPath));
- ViewCacheInfo viewCacheInfo = new ViewCacheInfo();
- viewCacheInfo.fullPath = fullPath;
- viewCacheInfo.gameObject = o;
- _ViewCacheInfos.Add(viewCacheInfo);
- }
- public static void HideView(string path)
- {
- string fullPath = "SmartBow/Prefabs/Views/" + path;
- _DestroyExistViews(fullPath);
- }
- private static void _DestroyExistViews(string fullPath)
- {
- _ViewCacheInfos.FindAll(e => e.fullPath == fullPath).ForEach(e =>
- {
- if (e.gameObject) Object.Destroy(e.gameObject);
- });
- _ViewCacheInfos.RemoveAll(e => e.fullPath == fullPath);
- }
- public const string Path_SettingsView = "Home/SettingsView";
- }
|