public void SetConfigType(ConfigBase <T> tp) { this.config_current = tp; configSetting = ConfigEditorAttribute.GetCurrentAttribute <ConfigEditorAttribute>(tp); this.titleContent = new GUIContent(string.IsNullOrEmpty(configSetting.EditorTitle) ? typeof(T).Name : configSetting.EditorTitle); fieldinfos = typeof(T).GetFields().ToList(); Chache = new List <ConfigEditorSchemaChache>(); foreach (var item in fieldinfos) { var infos = item.GetCustomAttributes(typeof(ConfigEditorFieldAttribute), true); ConfigEditorSchemaChache f = new ConfigEditorSchemaChache(); f.field_info = item; f.order = 0; if (infos.Length == 0) { continue; } else { ConfigEditorFieldAttribute cefa = (ConfigEditorFieldAttribute)infos[0]; f.order = cefa.Order; f.config_editor_field = cefa; } Chache.Add(f); } if (Chache.Count > 0) { Chache = Chache.OrderByDescending(x => x.order).ToList(); } initialized = true; }
public virtual void RenderRawLine(ConfigEditorSchemaChache data, object value, T raw) { //TODO 这里有个问题 有时候会为空 需要查 if (value == null) { return; } if (value.GetType().IsGenericType) { GUILayout.BeginVertical(GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(data.config_editor_setting.Width) }); int deleteIndex = -1; //Open Editor if (!string.IsNullOrEmpty(data.config_editor_setting.OutLinkEditor)) { if (GUILayout.Button(Language.Add)) { Assembly assembly = Assembly.GetExecutingAssembly(); IMultipleWindow e = assembly.CreateInstance(data.config_editor_setting.OutLinkEditor) as IMultipleWindow; if (e == null) { ShowNotification(new GUIContent(Language.OutLinkIsNull)); } else { e.UpdateSelectModel(value, SetListItemValue); e.ShowUtility(); } } var temp = value as List <int>; for (int i = 0; i < temp.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Label(GetOutLinkDisplayField(temp[i], data.config_editor_setting.OutLinkClass, data.config_editor_setting.OutLinkDisplay)); if (GUILayout.Button("X", GUILayout.Width(18))) { deleteIndex = i; } GUILayout.EndHorizontal(); } if (deleteIndex != -1) { temp.RemoveAt(deleteIndex); } } else { Type t = value.GetType().GetGenericArguments()[0]; if (value == null) { value = Activator.CreateInstance(t); data.field_info.SetValue(raw, value); } var addMethod = value.GetType().GetMethod("Add"); var removeMethod = value.GetType().GetMethod("RemoveAt"); if (GUILayout.Button(Language.Add)) { addMethod.Invoke(value, new object[] { t == typeof(string) ? string.Empty : Activator.CreateInstance(t) }); } int count = Convert.ToInt32(value.GetType().GetProperty("Count").GetValue(value, null)); int removeIndex = -1; for (int i = 0; i < count; i++) { object listItem = value.GetType().GetProperty("Item").GetValue(value, new object[] { i }); GUILayout.BeginHorizontal(); RenderBaseControl(data.config_editor_setting.Width - 18, data.config_editor_setting.CanEditor, listItem, v => { value.GetType().GetProperty("Item").SetValue(value, v, new object[] { i }); }); if (GUILayout.Button("X", new GUILayoutOption[] { GUILayout.Width(18) })) { removeIndex = i; } GUILayout.EndHorizontal(); } if (removeIndex != -1) { removeMethod.Invoke(value, new object[] { removeIndex }); } } GUILayout.EndVertical(); } else { //Open Editor if (!string.IsNullOrEmpty(data.config_editor_setting.OutLinkEditor)) { data.field_info.SetValue(raw, GetSingleSelectValueByFlag(raw.ID, data.field_info.Name, (int)value)); string buttonName = GetOutLinkDisplayField((int)value, data.config_editor_setting.OutLinkClass, data.config_editor_setting.OutLinkDisplay); if (GUILayout.Button(buttonName, new GUILayoutOption[] { GUILayout.Width(data.config_editor_setting.Width) })) { Assembly assembly = Assembly.GetExecutingAssembly(); IMultipleWindow e = assembly.CreateInstance(data.config_editor_setting.OutLinkEditor) as IMultipleWindow; if (e == null) { ShowNotification(new GUIContent(Language.OutLinkIsNull)); } else { AddSingleSelectFlag(raw.ID, data.field_info.Name); e.UpdateSelectModel(SingleTempSelect, SetListItemValue); e.ShowUtility(); } } } else { RenderBaseControl(data.config_editor_setting.Width, data.config_editor_setting.CanEditor, value, v => { data.field_info.SetValue(raw, v); }); } } }
public void SetConfigType(ConfigBase <T> tp) { this.config_current = tp; configSetting = ConfigEditorAttribute.GetCurrentAttribute <ConfigEditorAttribute>(tp) ?? new ConfigEditorAttribute(); this.titleContent = new GUIContent(string.IsNullOrEmpty(configSetting.Setting.EditorTitle) ? typeof(T).Name : configSetting.Setting.EditorTitle); fieldinfos = typeof(T).GetFields().ToList(); Chache = new List <ConfigEditorSchemaChache>(); foreach (var item in fieldinfos) { var infos = item.GetCustomAttributes(typeof(ConfigEditorFieldAttribute), true); ConfigEditorSchemaChache f = new ConfigEditorSchemaChache(); f.field_info = item; f.order = 0; if (infos.Length == 0) { int id = (int)GetCurrentFieldType(item.FieldType); f.config_editor_setting = Utility.GetDefaultControlConfig().SearchByID(id); if (f.config_editor_setting == null) { Log("Can't find default control id :" + id); } else { if (!f.config_editor_setting.Visibility) { continue; } } } else { ConfigEditorFieldAttribute cefa = (ConfigEditorFieldAttribute)infos[0]; f.order = cefa.Setting.Order; f.config_editor_setting = cefa.Setting; if (f.config_editor_setting.Width == 0) { int id = (int)GetCurrentFieldType(item.FieldType); var setting = Utility.GetDefaultControlConfig().SearchByID(id); f.config_editor_setting.Width = setting.Width; } if (!cefa.Setting.Visibility) { continue; } } Chache.Add(f); } if (Chache.Count > 0) { Chache = Chache.OrderByDescending(x => x.order).ToList(); } initialized = true; }
public virtual void RenderRawLine(ConfigEditorSchemaChache data, object value, T raw) { if (data.config_editor_field == null) { //EditorGUILayout.LabelField(((bool)value).ToString(), new GUILayoutOption[] { GUILayout.Width(80) }); EditorGUILayout.LabelField("", new GUILayoutOption[] { GUILayout.Width(80) }); return; } if (value.GetType().IsGenericType) { if (GUILayout.Button("Generic", new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) })) { } } if (value.GetType().IsEnum) { if (data.config_editor_field.CanEditor) { value = EditorGUILayout.EnumPopup(value as Enum, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); data.field_info.SetValue(raw, value); } else { EditorGUILayout.LabelField((value as Enum).ToString(), new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); } } if (value is string) { if (data.config_editor_field.CanEditor) { value = EditorGUILayout.TextField(value as string, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); data.field_info.SetValue(raw, value); } else { EditorGUILayout.LabelField(value as string, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); } } if (value is float) { if (data.config_editor_field.CanEditor) { value = EditorGUILayout.FloatField((float)value, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); data.field_info.SetValue(raw, value); } else { EditorGUILayout.LabelField(value as string, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); } } if (value is int) { if (data.config_editor_field.CanEditor) { value = EditorGUILayout.IntField((int)value, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); data.field_info.SetValue(raw, value); } else { EditorGUILayout.LabelField(value as string, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); } } if (value is bool) { if (data.config_editor_field.CanEditor) { value = EditorGUILayout.Toggle((bool)value, new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); data.field_info.SetValue(raw, value); } else { EditorGUILayout.LabelField(((bool)value).ToString(), new GUILayoutOption[] { GUILayout.Width(data.config_editor_field.Width) }); } } }