| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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 GameObject getGameObjectAndShowView(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);
- 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";
- }
|