private void SaveState() { OnlineMaps api = OnlineMaps.instance; OnlineMapsXML prefs = new OnlineMapsXML("Map"); // Save position and zoom OnlineMapsXML generalSettings = prefs.Create("General"); generalSettings.Create("Coordinates", api.position); generalSettings.Create("Zoom", api.zoom); // Save 2D markers api.SaveMarkers(prefs); // Save 3D markers api.GetComponent <OnlineMapsControlBase3D>().SaveMarkers3D(prefs); // Save settings to PlayerPrefs PlayerPrefs.SetString(key, prefs.outerXml); }
private void DrawSaveGUI(ref bool dirty) { EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.LabelField("Save state:"); saveSettings = EditorGUILayout.Toggle("Settings", saveSettings); if (allowSaveTexture) { saveTexture = EditorGUILayout.Toggle("Texture", saveTexture); } saveControl = EditorGUILayout.Toggle("Control", saveControl); saveMarkers = EditorGUILayout.Toggle("Markers", saveMarkers); if (allowSaveMarkers3D) { saveMarkers3D = EditorGUILayout.Toggle("Markers 3D", saveMarkers3D); } if (allowSaveLocationService) { saveLocationService = EditorGUILayout.Toggle("Location Service", saveLocationService); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save state")) { if (allowSaveTexture && saveTexture) { api.Save(); string path = AssetDatabase.GetAssetPath(api.texture); File.WriteAllBytes(path, api.texture.EncodeToPNG()); AssetDatabase.Refresh(); } OnlineMapsXML prefs = new OnlineMapsXML("OnlineMaps"); if (saveSettings) { api.SaveSettings(prefs); } if (saveControl) { api.GetComponent <OnlineMapsControlBase>().SaveSettings(prefs); } if (saveMarkers) { api.SaveMarkers(prefs); } if (allowSaveMarkers3D && saveMarkers3D) { api.GetComponent <OnlineMapsControlBase3D>().SaveMarkers3D(prefs); } if (allowSaveLocationService && saveLocationService) { api.GetComponent <OnlineMapsLocationService>().Save(prefs); } OnlineMapsPrefs.Save(prefs.outerXml); ResetSaveSettings(); dirty = true; } if (GUILayout.Button("Cancel", GUILayout.ExpandWidth(false))) { ResetSaveSettings(); dirty = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }