public SProfiler() { ColumnProp[] propArray1 = new ColumnProp[6]; ColumnProp prop = new ColumnProp { name = "NAME", width = 260 }; propArray1[0] = prop; ColumnProp prop2 = new ColumnProp { name = "TIME", width = 120 }; propArray1[1] = prop2; ColumnProp prop3 = new ColumnProp { name = "SELF TIME", width = 120 }; propArray1[2] = prop3; ColumnProp prop4 = new ColumnProp { name = "MAX", width = 80 }; propArray1[3] = prop4; ColumnProp prop5 = new ColumnProp { name = "MAX SELF", width = 80 }; propArray1[4] = prop5; ColumnProp prop6 = new ColumnProp { name = "COUNT", width = 80 }; propArray1[5] = prop6; this.column_props = propArray1; this.curSortType = SortType.Time; this.highToLow = true; }
/// <summary> /// 获取所有需要生成文件的类型 /// </summary> static Dictionary <Type, TableMapping> GetTypes() { var exclude = new List <string> { "UnityEngine", "UnityEngine.UI", }; bool IsExcluded(Type type) { var fullName = type.FullName; for (int i = 0; i < exclude.Count; i++) { if (fullName.Contains(exclude[i])) { return(true); } } return(false); } //获取所有(非委托丶非接口丶非枚举)类型 var types = (from assembly in AppDomain.CurrentDomain.GetAssemblies() where !(assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder) from type in assembly.GetExportedTypes() where !IsExcluded(type) && type.BaseType != typeof(MulticastDelegate) && !type.IsInterface && !type.IsEnum select type); //遍历, 生成代码信息 var dict = new Dictionary <Type, TableMapping>(); foreach (var type in types) { if (!type.IsPublic && !type.IsNestedPublic) { continue; } if (type.IsAbstract && type.IsSealed) { //静态类(抽象类丶密封类) var configs = new List <Config>(); foreach (var field in type.GetFields()) { var attr = (TableConfigAttribute)field.GetCustomAttributes(typeof(TableConfigAttribute), false).FirstOrDefault(); if (attr != null) { var v = field.GetValue(null) as IEnumerable <Config>; configs.AddRange(v); } } foreach (var prop in type.GetProperties()) { var attr = (TableConfigAttribute)prop.GetCustomAttributes(typeof(TableConfigAttribute), false).FirstOrDefault(); if (attr != null) { var v = prop.GetValue(null) as IEnumerable <Config>; configs.AddRange(v); } } //生成 var prop_pk = typeof(Column).GetProperty("IsPK"); var prop_autoinc = typeof(Column).GetProperty("IsAutoInc"); var prop_unique = typeof(Column).GetProperty("IsUnique"); var prop_def = typeof(Column).GetProperty("DefaultValue"); var prop_max_len = typeof(Column).GetProperty("MaxLength"); var prop_auto_create = typeof(Column).GetProperty("IsAutoCreateIns"); var prop_pk_sql = typeof(TableMapping).GetProperty("GetByPrimaryKeySql"); foreach (var c in configs) { //Name var c_type = c.Type; var table_name = c?.Name ?? c_type.FullName.Replace(".", "_").Replace("+", "_"); //Colums var props = c_type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); var fields = c_type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetField | BindingFlags.GetField); var cols = new List <Column>(); Column pk = null; foreach (var prop in props) { var name = prop.Name; if (!prop.CanWrite || c.Ignores != null && c.Ignores.Contains(name)) { continue; } var col = new ColumnProp(prop); prop_pk.SetValue(col, c.PK == name); prop_autoinc.SetValue(col, c.PK == name && c.AutoInc); prop_unique.SetValue(col, c.Uniques != null && c.Uniques.Contains(name)); prop_def.SetValue(col, c.DefaultValues != null && c.DefaultValues.ContainsKey(name) ? c.DefaultValues[name] : null); prop_max_len.SetValue(col, c.MaxLengths != null && c.MaxLengths.ContainsKey(name) ? c.MaxLengths[name] : null); prop_auto_create.SetValue(col, c.AllAutoCreateIns); cols.Add(col); if (col.IsPK) { pk = col; } } foreach (var field in fields) { var name = field.Name; if (!field.IsPublic || c.Ignores != null && c.Ignores.Contains(name)) { continue; } var col = new ColumnField(field); prop_pk.SetValue(col, c.PK == name); prop_autoinc.SetValue(col, c.PK == name && c.AutoInc); prop_unique.SetValue(col, c.Uniques != null && c.Uniques.Contains(name)); prop_def.SetValue(col, c.DefaultValues != null && c.DefaultValues.ContainsKey(name) ? c.DefaultValues[name] : null); prop_max_len.SetValue(col, c.MaxLengths != null && c.MaxLengths.ContainsKey(name) ? c.MaxLengths[name] : null); prop_auto_create.SetValue(col, c.AllAutoCreateIns); cols.Add(col); if (col.IsPK) { pk = col; } } var mapping = new TableMapping(c_type, table_name, cols.ToArray(), pk); //PK if (pk != null) { prop_pk_sql.SetValue(mapping, string.Format("SELECT * FROM \"{0}\" WHERE \"{1}\" = ?", mapping.TableName, pk.Name)); } else { prop_pk_sql.SetValue(mapping, string.Format("SELECT * FROM \"{0}\" LIMIT 1", mapping.TableName)); } //添加到列表 if (dict.ContainsKey(c_type)) { dict.Remove(c_type); Debug.LogWarning(string.Format("Type '{0}' has multiple config", c_type)); } dict.Add(c_type, mapping); } } else { //实例类 var attrs = type.GetCustomAttributes(typeof(TableAttribute), false); if (attrs.Length > 0) { //添加到列表 if (dict.ContainsKey(type)) { Debug.LogWarning(string.Format("Type '{0}' has multiple config", type)); dict.Remove(type); } dict.Add(type, new TableMemMapping(type)); } } } return(dict); }
private void DrawGroups() { string str = string.Empty; string str2 = string.Empty; string str3 = string.Empty; string str4 = string.Empty; string str5 = string.Empty; string str6 = string.Empty; string str7 = string.Empty; for (int i = 0; i < groupList.Count; i++) { Group group = groupList[i]; group.flush(); str = str + group.name + "\n"; str2 = str2 + group.time.ToString("F2"); if (this.showPercent) { str2 = (str2 + " (") + group.timePercent.ToString("F2") + "%)"; } str2 = str2 + "\n"; str3 = str3 + group.selfTime.ToString("F2"); if (this.showPercent) { str3 = (str3 + " (") + group.selfTimePercent.ToString("F2") + "%)"; } str3 = str3 + "\n"; str7 = group.maxTime.ToString("F2"); if (group.maxTime > 5.0) { str4 = (str4 + "<color=red>") + str7 + "</color>"; } else { str4 = str4 + str7; } str4 = str4 + "\n"; str7 = group.maxSelfTime.ToString("F2"); if (group.maxSelfTime > 5.0) { str5 = (str5 + "<color=red>") + str7 + "</color>"; } else { str5 = str5 + str7; } str5 = str5 + "\n"; str6 = str6 + ((string)group.count) + "\n"; } this.column_props[0].data = str; this.column_props[1].data = str2; this.column_props[2].data = str3; this.column_props[3].data = str4; this.column_props[4].data = str5; this.column_props[5].data = str6; float left = 20f; float top = 30f; float height = Screen.height - top; GUI.color = Color.green; for (int j = 0; j < this.column_props.Length; j++) { ColumnProp prop = this.column_props[j]; GUI.Label(new Rect(left, top, (float)prop.width, height), prop.data); if (GUI.Button(new Rect(left, 0f, (float)prop.width, top), prop.name)) { if (this.curSortType == j) { this.highToLow = !this.highToLow; } else { this.curSortType = (SortType)j; } } left += prop.width + 10f; } float width = 80f; if (GUI.Button(new Rect(left, 0f, width, top), "SHOW %")) { this.showPercent = !this.showPercent; } left += width + 10f; if (GUI.Button(new Rect(left, 0f, width, top), "RESET")) { Reset(); } left += width + 10f; GUI.color = !paused ? GUI.color : Color.red; if (GUI.Button(new Rect(left, 0f, width, top), "PAUSE")) { paused = !paused; } GUI.color = Color.white; }