public void LoadUI(Type ui_type, object context = null, bool needwait = false) { if (ui_type == null || !ui_type.IsSubclassOf(typeof(CGameUI))) { return; } string ui_name = rg.Match(ui_type.Name).Value; CGameUI exists = Global.ui_mgr.Get(ui_name) as CGameUI; if (exists != null) { exists.context = context;//在界面还没有show前赋值所传的参数列表 if (!exists.IsShow()) { exists.Show(); } exists.LoadUICallback(); return; } // 防止重复加载 if (IsLoading(ui_name)) { return; } CGameUIAsset asset = CResourceFactory.CreateInstance <CGameUIAsset>(string.Format("res/ui/uiprefab/{0}.ui", ui_name).ToLower(), null); AddLoading(ui_name, asset); asset.RegisterCompleteCallback(delegate(CGameUIAsset e) { CGameUI ui = e.gameObject.AddComponent(ui_type) as CGameUI; ui.SetName(ui_name); ui.SetAsset(e); ui.context = context; Global.ui_mgr.Add(ui); ui.LoadUICallback(); RemoveLoading(ui_name); }); }
public void Add(CGameUI ui) { if (!index_pool.CanAlloc()) { LOG.TraceRed("ERROR: ui数量超出上限。ui name:{0}", ui.Name); return; } int index = index_pool.Alloc(); if (uis[index] != null) { throw new Exception(string.Format("[CUIManager] ui index:{0} is already in use", index)); } if (names.ContainsKey(ui.Name)) { throw new Exception(string.Format("[CUIManager] ui name:{0} is already exist", ui.Name)); } uis[index] = ui; names[ui.Name] = ui; ui.index = index; ui.SetPosition(new Vector3((ui.index + 1) * 100, 0, 0)); // 最后显示该ui ui.Show(); }