Ejemplo n.º 1
0
    private void DrawSaveGUI(ref bool dirty)
    {
        EditorGUILayout.BeginVertical(GUI.skin.box);

        EditorGUILayout.LabelField("Save state:");
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("All", GUILayout.ExpandWidth(false)))
        {
            foreach (OnlineMapsSavableItem item in savableItems)
            {
                item.enabled = true;
            }
        }
        if (GUILayout.Button("None", GUILayout.ExpandWidth(false)))
        {
            foreach (OnlineMapsSavableItem item in savableItems)
            {
                item.enabled = false;
            }
        }
        EditorGUILayout.Space();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        foreach (OnlineMapsSavableItem item in savableItems)
        {
            item.enabled = EditorGUILayout.Toggle(item.label, item.enabled);
        }

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Save state"))
        {
            try
            {
                OnlineMapsJSONObject obj = new OnlineMapsJSONObject();
                foreach (OnlineMapsSavableItem item in savableItems)
                {
                    if (!item.enabled)
                    {
                        continue;
                    }
                    if (item.jsonCallback != null)
                    {
                        obj.Add(item.name, item.jsonCallback());
                    }
                    if (item.invokeCallback != null)
                    {
                        item.invokeCallback();
                    }
                }
                OnlineMapsPrefs.Save(obj.ToString());
            }
            catch
            {
                // ignored
            }


            showSave = false;
            dirty    = true;
        }

        if (GUILayout.Button("Cancel", GUILayout.ExpandWidth(false)))
        {
            showSave = false;
            dirty    = true;
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.EndVertical();
    }
Ejemplo n.º 2
0
    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();
    }