public void Close(EUI eUI) { UIBase uIBase; if (!TryGetUIBase(eUI, out uIBase)) { return; } //取出界面,执行OnExit函数 QLog.LogEditor(StringPool.Format("{0} 执行OnExit函数", uIBase.eUI.ToString())); uIBase.OnExit(); UIBasePool.Remove(uIBase); GameObject.Destroy(uIBase.CacheGameObject); uIBase = null; //取出最后的界面,执行OnResume函数 UIBase lastUIBase; if (TryGetLastUIBase(out lastUIBase)) { QLog.LogEditor(StringPool.Format("{0} 执行OnResume函数", lastUIBase.eUI.ToString())); lastUIBase.OnResume(); } }
public void Close() { UIBase lastUIBase; if (TryGetLastUIBase(out lastUIBase)) { EUI eUI = lastUIBase.eUI; QLog.LogEditor(StringPool.Format("统一关闭 {0} .", eUI.ToString())); Close(eUI); } }
public void OnGroup(int pre, int cur) { QLog.LogEditor(StringPool.Format("点击pre = {0}, cur = {1}.", pre, cur)); //设置所有组件的显示隐藏 int length = list.Count; for (int i = 0; i < length; i++) { QToggleButton toggleButton = list[i]; toggleButton.SetChoose(cur); } //设置组件的回调函数 if (OnGroupAction != null) { OnGroupAction(pre, cur); } }
public void GenerateCodeEditor() { transformGroup.Clear(); Transform[] children = CacheTransform.GetComponentsInChildren <Transform>(true); for (int i = 0; i < children.Length; i++) { Transform child = children[i]; string fullName = child.name; string[] tmpName = fullName.Split('_'); if (tmpName.Length > 1) { Type type; if (name_type.TryGetValue(tmpName[0], out type)) { transformGroup.Add(child, type); } } } //读取 StreamReader streamReader = new StreamReader(UI_TEMPLATE_PATH, Encoding.UTF8); string ClassText = streamReader.ReadToEnd(); streamReader.Close(); //生成 UIBase uIBase = GetComponent <UIBase>(); string uiBasePath = StringPool.Format(Application.dataPath + "/Lemon/Scripts/UI/{0}/{1}_Generate.cs", uIBase.name, uIBase.name); StreamWriter streamWriter = new StreamWriter(uiBasePath, false, Encoding.UTF8); //添加自动化的变量 StringBuilder stringBuilder = StringPool.GetStringBuilder(); stringBuilder.Append("\n"); Dictionary <Transform, Type> .Enumerator enumerator = transformGroup.GetEnumerator(); while (enumerator.MoveNext()) { string name = enumerator.Current.Key.name; Type type = enumerator.Current.Value; stringBuilder.Append(" public " + type.Name + " " + name + "; "); stringBuilder.Append("\n"); } ClassText = ClassText.Replace("UITemplate", uIBase.name); ClassText = ClassText.Replace(KEY_VARIABLE, KEY_VARIABLE + stringBuilder.ToString()); //添加自动化的变量路径 stringBuilder = StringPool.GetStringBuilder(); stringBuilder.Append("\n"); enumerator = transformGroup.GetEnumerator(); while (enumerator.MoveNext()) { Transform childTransform = enumerator.Current.Key; Type type = enumerator.Current.Value; stringBuilder.Append(" " + childTransform.name + " = " + "CacheTransform.Find(\"" + UtilityEditor.GetPath(childTransform, CacheTransform) + "\").GetComponent<" + type.Name + ">();\n"); } ClassText = ClassText.Replace(KEY_PATH, KEY_PATH + stringBuilder.ToString()); streamWriter.Write(ClassText); streamWriter.Close(); UnityEditor.AssetDatabase.Refresh(); }
public void Open(EUI eUI, EUIDepth eUIDepth = EUIDepth.Default, params object[] objs) { UIBase uIBase; if (TryGetUIBase(eUI, out uIBase)) { QLog.LogWarning(StringPool.Concat("Already open UI, witch EUI is ", eUI.ToString())); return; } UIBase prefabDatabase = UnityEditor.AssetDatabase.LoadAssetAtPath <UIBase>(StringPool.Concat(PATH_PREFAB_UI, eUI.ToString(), ".prefab")); if (prefabDatabase == null) { QLog.LogError(StringPool.Concat("Can not find UIBase Script in EUI = ", eUI.ToString())); return; } uIBase = Object.Instantiate <UIBase>(prefabDatabase, UGUI.UGUICanvas.transform, false); if (uIBase == null) { QLog.LogError(StringPool.Concat("Instantiate fail, EUI = ", eUI.ToString())); return; } //设置数据,判断是否进入 uIBase.SetData(objs); if (!uIBase.IsCanEnter()) { QLog.Log(StringPool.Concat("The UIBase script can not enter, EUI = ", eUI.ToString())); return; } //取出最后的界面,执行OnPause函数 UIBase lastUIBase; if (TryGetLastUIBase(out lastUIBase)) { QLog.LogEditor(StringPool.Format("{0} 执行暂停函数", lastUIBase.eUI.ToString())); lastUIBase.OnPause(); } uIBase.CacheGameObject.SetActive(true); //设置层级 int tmpDepth; if (DepthPool.TryGetValue(eUIDepth, out tmpDepth)) { tmpDepth += DEPTH_BETWEEN_UI; DepthPool[eUIDepth] = tmpDepth; } else { tmpDepth += (int)eUIDepth + DEPTH_BETWEEN_UI; DepthPool.Add(eUIDepth, tmpDepth); } uIBase.SetDepth(eUI, eUIDepth, tmpDepth); QLog.LogEditor(StringPool.Format("{0} depth is {1}", uIBase.eUI.ToString(), tmpDepth.ToString())); //新界面,执行OnEnter函数 QLog.LogEditor(StringPool.Format("{0} 执行OnEnter函数", uIBase.eUI.ToString())); uIBase.OnEnter(); UIBasePool.Add(uIBase); }