static void AppendLoadDictMethod(StringBuilder sb, string schemaKey, Dictionary <string, object> schemaData) { sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel2)); sb.Append(GDECodeGenConstants.LoadDictMethod); sb.Append("\n"); bool shouldAppendSpace = false; bool didAppendSpaceForSection = false; bool isFirstSection = true; string variableType; // Append all the single variables first foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { variableType = fieldType.ToString(); List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString()); foreach (string fieldKey in fieldKeys) { AppendLoadVariable(sb, variableType, fieldKey); shouldAppendSpace = true; isFirstSection = false; } } // Append the custom types bool appendTempKeyDeclaration = true; foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey)) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType); variableType = string.Format(GDECodeGenConstants.DataClassNameFormat, variableType); if (appendTempKeyDeclaration) { sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel4)); sb.Append(GDECodeGenConstants.TempStringKeyDeclaration); sb.Append("\n"); appendTempKeyDeclaration = false; } AppendLoadCustomVariable(sb, variableType, fieldKey); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } didAppendSpaceForSection = false; // Append the basic lists foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { List <string> fieldKeys = GDEItemManager.SchemaListFieldKeysOfType(schemaKey, fieldType.ToString()); variableType = fieldType.ToString(); foreach (string fieldKey in fieldKeys) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } AppendLoadListVariable(sb, variableType, fieldKey); shouldAppendSpace = true; didAppendSpaceForSection = true; isFirstSection = false; } } didAppendSpaceForSection = false; // Append the custom lists foreach (string fieldKey in GDEItemManager.SchemaCustomListFields(schemaKey)) { if (shouldAppendSpace && !didAppendSpaceForSection && !isFirstSection) { sb.Append("\n"); } schemaData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out variableType); variableType = "Custom"; AppendLoadListVariable(sb, variableType, fieldKey); shouldAppendSpace = true; isFirstSection = false; didAppendSpaceForSection = true; } sb.Append("".PadLeft(GDECodeGenConstants.IndentLevel3)); sb.Append(GDECodeGenConstants.LoadDictMethodEnd); sb.Append("\n"); }
protected override void DrawEntry(string schemaKey, Dictionary <string, object> schemaData) { float beginningHeight = CurrentHeight(); // Start drawing below if (DrawFoldout(GDEConstants.SchemaLbl + " ", schemaKey, schemaKey, schemaKey, RenameSchema)) { bool shouldDrawSpace = false; bool didDrawSpaceForSection = false; // Draw the basic types foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { List <string> fieldKeys = GDEItemManager.SchemaFieldKeysOfType(schemaKey, fieldType.ToString()); foreach (string fieldKey in fieldKeys) { currentLinePosition += GDEConstants.Indent; DrawSingleField(schemaKey, fieldKey, schemaData); shouldDrawSpace = true; } } // Draw the custom types foreach (string fieldKey in GDEItemManager.SchemaCustomFieldKeys(schemaKey)) { if (shouldDrawSpace && !didDrawSpaceForSection) { NewLine(0.5f); didDrawSpaceForSection = true; } currentLinePosition += GDEConstants.Indent; DrawSingleField(schemaKey, fieldKey, schemaData); shouldDrawSpace = true; } didDrawSpaceForSection = false; // Draw the lists foreach (BasicFieldType fieldType in GDEItemManager.BasicFieldTypes) { List <string> fieldKeys = GDEItemManager.SchemaListFieldKeysOfType(schemaKey, fieldType.ToString()); foreach (string fieldKey in fieldKeys) { if (shouldDrawSpace && !didDrawSpaceForSection) { NewLine(0.5f); didDrawSpaceForSection = true; } currentLinePosition += GDEConstants.Indent; DrawListField(schemaKey, schemaData, fieldKey); shouldDrawSpace = true; } } didDrawSpaceForSection = false; // Draw the custom lists foreach (string fieldKey in GDEItemManager.SchemaCustomListFields(schemaKey)) { if (shouldDrawSpace && !didDrawSpaceForSection) { NewLine(0.5f); didDrawSpaceForSection = true; } currentLinePosition += GDEConstants.Indent; DrawListField(schemaKey, schemaData, fieldKey); shouldDrawSpace = true; } // Remove any fields that were deleted above foreach (string deletedKey in deletedFields) { RemoveField(schemaKey, schemaData, deletedKey); } deletedFields.Clear(); // Rename any fields that were renamed string error; string oldFieldKey; string newFieldKey; foreach (KeyValuePair <List <string>, Dictionary <string, object> > pair in renamedFields) { oldFieldKey = pair.Key[0]; newFieldKey = pair.Key[1]; if (!GDEItemManager.RenameSchemaField(oldFieldKey, newFieldKey, schemaKey, pair.Value, out error)) { EditorUtility.DisplayDialog(GDEConstants.ErrorLbl, string.Format("Couldn't rename {0} to {1}: {2}", oldFieldKey, newFieldKey, error), GDEConstants.OkLbl); } } renamedFields.Clear(); NewLine(); DrawAddFieldSection(schemaKey, schemaData); NewLine(2f); GUIContent content = new GUIContent(GDEConstants.DeleteBtn); float width = GUI.skin.button.CalcSize(content).x; if (GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content)) { deletedSchemas.Add(schemaKey); } NewLine(); DrawSectionSeparator(); NewLine(0.25f); } float groupHeight = CurrentHeight() - beginningHeight; SetGroupHeight(schemaKey, groupHeight); }