private void SaveFile(string filePath) { BlockMenuDataManager bm = BlockMenuDataManager.Instance; //string json = JsonUtility.ToJson(bm.menu); //string json = JsonWriter.Serialize(bm.menu); //string json = bm.menu.buildJsonObject().Print(); string json = JsonUtil.Serialize(bm.menu, true, true); FileStream file; if (File.Exists(filePath)) { File.Delete(filePath); } file = File.Create(filePath); StreamWriter sw = new StreamWriter(file); sw.Write(json); sw.Close(); file.Close(); }
private void DrawBlockButton(BlockButtonData button, int quadrant, int level) { BlockMenuDataManager bm = BlockMenuDataManager.Instance; GUI.changed = false; button.buttonId = EditorGUILayout.TextField("Button ID", button.buttonId); button.buttonName = EditorGUILayout.TextField("Button Name", button.buttonName); button.buttonColor = EditorGUILayout.ColorField("Button Color", button.buttonColor); button.buttonPic = EditorGUILayout.TextField("Button Pic", button.buttonPic); button.canClick = EditorGUILayout.Toggle("Can Click?", button.canClick); if (GUI.changed) { dirty = true; } if (button.subPanel == null) { if (GUILayout.Button("Create Sub Panel")) { button.subPanel = new BlockPanelData(); dirty = true; } } else { DrawBlockPanel(button.subPanel, level + 1, quadrant); } }
private void LoadFile(string filePath) { FileStream file = File.OpenRead(filePath); BlockMenuDataManager bm = BlockMenuDataManager.Instance; StreamReader sr = new StreamReader(file); string json = sr.ReadToEnd(); sr.Close(); file.Close(); //bm.menu = JsonUtility.FromJson<BlockMenuData>(json); //bm.menu = JsonReader.Deserialize<BlockMenuData>(json); bm.menu = JsonUtil.Deserialize <BlockMenuData>(json); /* * bm.menu = new BlockMenuData(); * JSONObject obj = new JSONObject(json); * bm.menu.parseJsonObject(obj); */ }
private void ShowMenuEditor() { BlockMenuDataManager bm = BlockMenuDataManager.Instance; if (bm.menu == null) { return; } GUI.changed = false; bm.menu.name = EditorGUILayout.TextField("Menu Name", bm.menu.name); if (GUI.changed) { dirty = true; } int level = 1; if (bm.menu.rootPanel == null) { if (GUILayout.Button("Create Root Panel")) { BlockPanelData panel = new BlockPanelData(); bm.menu.rootPanel = panel; dirty = true; } } else { DrawBlockPanel(bm.menu.rootPanel, level); } }
void OnGUI() { BlockMenuDataManager bm = BlockMenuDataManager.Instance; scrollPos = EditorGUILayout.BeginScrollView(scrollPos); if (GUILayout.Button("Load Menu Data")) { if (bm.menu != null && dirty) { if (!EditorUtility.DisplayDialog("confirm", "Current menu has not been saved. Give up all changes and load menu?", "Yes", "Cancel")) { return; } } string[] filter = { "JSon files", "json" }; filePath = EditorUtility.OpenFilePanelWithFilters("Load JSon", defaultFilePath, filter); Debug.Log("File:" + filePath); if (filePath == null) { return; } LoadFile(filePath); dirty = false; } if (GUILayout.Button("Create Mew Menu")) { if (bm.menu != null && dirty) { if (!EditorUtility.DisplayDialog("confirm", "Current menu has not been saved. Give up all changes and create new menu?", "Yes", "Cancel")) { return; } } string[] filter = { "JSon files", "json" }; filePath = EditorUtility.SaveFilePanel("Save JSon", defaultFilePath, "New Menu", "json"); if (filePath != null) { Debug.Log("File:" + filePath); bm.menu = new BlockMenuData(); SaveFile(filePath); dirty = false; } } if (GUILayout.Button("Save Menu")) { if (dirty && filePath != null) { SaveFile(filePath); dirty = false; } } if (GUILayout.Button("Clean Menu")) { if (dirty && filePath != null) { if (bm.menu != null && dirty) { if (!EditorUtility.DisplayDialog("confirm", "Current menu has not been saved. Give up all changes?", "Yes", "Cancel")) { return; } } } bm.menu = null; dirty = false; filePath = null; } ShowMenuEditor(); EditorGUILayout.EndScrollView(); }