/// <summary> /// 卸载模块 /// </summary> /// <param name="moduleName"></param> private void UnloadModule(string moduleName) { if (!_uiModules.ContainsKey(moduleName)) { Debug.LogError("当前模块不存在,无法卸载..."); return; } //获取该模块 UIModuleBase moduleBase = _uiModules[moduleName]; //从字典里移除 _uiModules.Remove(moduleName); //将该对象销毁 Object.Destroy(moduleBase.gameObject); }
/// <summary> /// 加载模块 /// </summary> /// <param name="moduleName"></param> private void LoadModule(string moduleName, Vector2 anchoredPosition) { //如果字典中根本没有该模块,或字典里该模块的值为空 if (!_uiModules.ContainsKey(moduleName) || _uiModules[moduleName] == null) { //通过模块名称获取对应的资源路径 string panelPath = UIConfigurationManager.GetInstance().GetPanelPrefabPathByName(moduleName); //加载预设体,并生成对应的对象 GameObject module = PrefabManager.GetInstance().CreateGameObjectByPrefab(panelPath, _canvas, anchoredPosition); //修改模块的名称,去掉(Clone) module.name = moduleName; //获取模块组件 UIModuleBase moduleBase = module.GetComponent <UIModuleBase>(); //添加到字典里 _uiModules[moduleName] = moduleBase; } }
/// <summary> /// 控制器启动 /// </summary> /// <param name="module"></param> public virtual void ControllerStart(UIModuleBase module) { _module = module; }