public static int GetNewGraphId() { if (File.Exists(GraphRecordFilePath)) { string jsonString = File.ReadAllText(GraphRecordFilePath); GraphRecord graphRecord = new GraphRecord(); EditorJsonUtility.FromJsonOverwrite(jsonString, graphRecord); return(graphRecord.nextGraphId); } return(0); }
public static List <GraphBaseInfo> LoadGraphBaseInfoList() { if (File.Exists(GraphRecordFilePath)) { string jsonString = File.ReadAllText(GraphRecordFilePath); GraphRecord graphRecord = new GraphRecord(); EditorJsonUtility.FromJsonOverwrite(jsonString, graphRecord); return(graphRecord.graphBaseInfoList); } return(null); }
private static void AddOrUpdateGraphsRecord(GraphEditorData data) { if (File.Exists(GraphRecordFilePath)) { string jsonString = File.ReadAllText(GraphRecordFilePath); GraphRecord graphRecord = new GraphRecord(); EditorJsonUtility.FromJsonOverwrite(jsonString, graphRecord); bool hasFoundGraph = false; for (int i = 0; i < graphRecord.graphBaseInfoList.Count; i++) { if (graphRecord.graphBaseInfoList[i].graphId == data.graphId) { hasFoundGraph = true; graphRecord.graphBaseInfoList[i].graphName = data.graphName; graphRecord.graphBaseInfoList[i].graphDescription = data.graphDescription; break; } } if (!hasFoundGraph) { graphRecord.graphBaseInfoList.Add(new GraphBaseInfo { graphId = data.graphId, graphName = data.graphName, graphDescription = data.graphDescription }); graphRecord.nextGraphId++; } jsonString = EditorJsonUtility.ToJson(graphRecord, true); File.WriteAllText(GraphRecordFilePath, jsonString); } else { GraphRecord graphRecord = new GraphRecord(); graphRecord.graphBaseInfoList = new List <GraphBaseInfo>(); graphRecord.graphBaseInfoList.Add(new GraphBaseInfo() { graphId = data.graphId, graphName = data.graphName, graphDescription = data.graphDescription }); graphRecord.nextGraphId++; string jsonString = EditorJsonUtility.ToJson(graphRecord, true); File.WriteAllText(GraphRecordFilePath, jsonString); } AssetDatabase.Refresh(); }
private static void RemoveGraphInfoInRecord(int graphId) { if (File.Exists(GraphRecordFilePath)) { string jsonString = File.ReadAllText(GraphRecordFilePath); GraphRecord graphRecord = new GraphRecord(); EditorJsonUtility.FromJsonOverwrite(jsonString, graphRecord); for (int i = 0; i < graphRecord.graphBaseInfoList.Count; i++) { if (graphRecord.graphBaseInfoList[i].graphId == graphId) { graphRecord.graphBaseInfoList.RemoveAt(i); jsonString = EditorJsonUtility.ToJson(graphRecord, true); File.WriteAllText(GraphRecordFilePath, jsonString); AssetDatabase.Refresh(); return; } } } }