using System.Collections; using System.Collections.Generic; using UnityEngine; public class ViewManager2 { private class ViewCacheInfo { public string fullPath; public GameObject gameObject; } private static List _ViewCacheInfos = new(); public static void ShowView(string path) { string fullPath = "SmartBow/Prefabs/Views/" + path; _DestroyExistViews(fullPath); GameObject o = Object.Instantiate(Resources.Load(fullPath)); ViewCacheInfo viewCacheInfo = new ViewCacheInfo(); viewCacheInfo.fullPath = fullPath; viewCacheInfo.gameObject = o; _ViewCacheInfos.Add(viewCacheInfo); } public static GameObject getGameObjectAndShowView(string path) { string fullPath = "SmartBow/Prefabs/Views/" + path; _DestroyExistViews(fullPath); GameObject o = Object.Instantiate(Resources.Load(fullPath)); ViewCacheInfo viewCacheInfo = new ViewCacheInfo(); viewCacheInfo.fullPath = fullPath; viewCacheInfo.gameObject = o; _ViewCacheInfos.Add(viewCacheInfo); return o; } 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 static void RemoveView(string path) { string fullPath = "SmartBow/Prefabs/Views/" + path; _RemoveView(fullPath); } //仅移除 _ViewCacheInfos private static void _RemoveView(string fullPath) { _ViewCacheInfos.RemoveAll(e => e.fullPath == fullPath); } public const string Path_SettingsView = "Home/SettingsView"; public const string Path_SocialView = "Home/SocialView"; public const string Path_PersonalView = "Home/PersonalView"; public const string Path_RankingView = "Home/RankingView"; public const string Path_ConnectGuidanceView = "Home/ConnectGuidanceView"; public const string Path_GyrGuidanceView = "Home/GyrGuidanceView"; public const string Path_MagGuidanceView = "Home/MagGuidanceView"; public const string Path_InfraredView = "Home/InfraredView"; public const string Path_InfraredScreenPositioningView = "Home/InfraredScreenPositioningView"; public const string Path_HomeViewTip = "Home/HomeView_Tip"; public const string Path_GameResultView = "GameResultView"; }