public void Awake(GameObject gameObject, PanelConfig config) { this.GameObject = gameObject; this.BindRoot = new UIBindRoot(gameObject, config.BindViewType); this.PanelId = config.PanelId; this.PanelType = config.PanelType; this.PanelLifespan = config.PanelLifespan; gameObject.SetActive(false); }
public async Task Load(PanelId panelId, bool showWhenDone = true, object param = null) { try { Panel panel; if (this.panelCache.TryGetValue(panelId, out panel)) { if (panel.PanelLifespan == PanelLifespan.Dynamic) { this.dynamicPanelIds.Remove(panelId); } if (!panel.IsShow && showWhenDone) { panel.OnShow(param); } return; } if (this.isLoading.Contains(panelId)) { Debug.LogWarning($"Panel {panelId} is already loading."); return; } this.isLoading.Add(panelId); Type type = this.panelTypes[panelId]; PanelConfig config = this.panelConfigs[panelId]; await BK.Game.ResourcesComponent.LoadBundleAsync($"{panelId}"); GameObject go = GameObject.Instantiate((GameObject)Game.ResourcesComponent.GetAsset($"{panelId}", $"{panelId}.prefab")); panel = (Panel)ObjectFactory.CreateEntity(type); panel.Awake(go, config); this.isLoading.Remove(panelId); this.panelCache.Add(panelId, panel); if (showWhenDone) { panel.OnShow(param); } return; } catch (Exception e) { throw new Exception($"{panelId} UI 错误: {e}"); } }
PanelConfigAttribute(PanelId panelId, PanelType panelType, Type bindViewType, PanelLifespan panelLifespan = PanelLifespan.Dynamic) { PanelConfig = new PanelConfig(panelId, panelType, bindViewType, panelLifespan); }