123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using UnityEngine;
- using Player.Wallet;
- /* 静态类,用于全局访问和管理游戏中的各类核心管理器 */
- public static class ComponentsManager
- {
- // 钱包管理器存储
- private static Storage<Wallet> _wallet = new Storage<Wallet>();
- // 主菜单UI管理器存储
- private static Storage<MenuUI> _menuUI = new Storage<MenuUI>();
- // 玩家数据管理器存储
- private static Storage<PlayerData> _playerData = new Storage<PlayerData>();
- // 游戏主UI管理器存储
- private static Storage<GameUI> _gameUI = new Storage<GameUI>();
- // 关卡管理器存储
- private static Storage<StagesManager> _stagesManager = new Storage<StagesManager>();
- // 玩家军队管理器存储
- private static Storage<PlayerArmyManager> _playerArmyManager = new Storage<PlayerArmyManager>();
- // 战斗管理器存储
- private static Storage<BattleManager> _battleManager = new Storage<BattleManager>();
- // 摄像机控制脚本存储
- private static Storage<CameraScript> _cameraScript = new Storage<CameraScript>();
- // 升级UI管理器存储
- private static Storage<UpgradeUI> _upgradeUI = new Storage<UpgradeUI>();
- // 教程引导管理器存储
- private static Storage<Tutorial> _tutorial = new Storage<Tutorial>();
- // 全局访问:玩家钱包
- public static Wallet PlayerWallet => _wallet.GetItem();
- // 全局访问:主菜单UI
- public static MenuUI MenuUI => _menuUI.GetItem();
- // 全局访问:玩家数据
- public static PlayerData PlayerData => _playerData.GetItem();
- // 全局访问:游戏主UI
- public static GameUI GameUI => _gameUI.GetItem();
- // 全局访问:关卡管理器
- public static StagesManager StagesManager => _stagesManager.GetItem();
- // 全局访问:玩家军队管理器
- public static PlayerArmyManager PlayerArmyManager => _playerArmyManager.GetItem();
- // 全局访问:战斗管理器
- public static BattleManager BattleManager => _battleManager.GetItem();
- // 全局访问:摄像机控制脚本
- public static CameraScript CameraScript => _cameraScript.GetItem();
- // 全局访问:升级UI
- public static UpgradeUI UpgradeUI => _upgradeUI.GetItem();
- // 全局访问:教程引导
- public static Tutorial Tutorial => _tutorial.GetItem();
- /// <summary>
- /// 泛型存储类,用于延迟查找和缓存各类管理器对象
- /// </summary>
- private class Storage<T> where T : Object
- {
- // 缓存的管理器对象
- private T _item;
- /// <summary>
- /// 获取管理器对象,若未缓存则自动查找并缓存
- /// </summary>
- /// <returns>类型为T的管理器对象</returns>
- public T GetItem()
- {
- if (_item == null)
- {
- _item = Object.FindObjectOfType<T>();
- }
- return _item;
- }
- }
- }
|