GroundPlaneLayoutConfigurationEditor.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.IO;
  6. namespace Ximmerse.XR.Tag
  7. {
  8. [CustomEditor(typeof(GroundPlaneLayoutConfiguration))]
  9. public class GroundPlaneLayoutConfigurationEditor : Editor
  10. {
  11. GroundPlaneLayoutConfiguration tScript
  12. {
  13. get => this.target as GroundPlaneLayoutConfiguration;
  14. }
  15. private void OnEnable()
  16. {
  17. }
  18. public override void OnInspectorGUI()
  19. {
  20. base.OnInspectorGUI();
  21. EditorGUILayout.BeginHorizontal();
  22. if (GUILayout.Button("Export to JSON"))
  23. {
  24. string json = (JsonUtility.ToJson(tScript.layout, true));
  25. string path = EditorUtility.SaveFilePanel("Save Json", "Assets", "groundplane-layout", "json");
  26. if (!string.IsNullOrEmpty(path))
  27. {
  28. File.WriteAllText(path, json);
  29. Debug.Log(json);
  30. Debug.LogFormat("Writes to {0}", path);
  31. }
  32. }
  33. if (GUILayout.Button("Import from JSON"))
  34. {
  35. string file = EditorUtility.OpenFilePanel("Open GroundPlane layout json file", "Assets", "json");
  36. if (!string.IsNullOrEmpty(file))
  37. {
  38. var layout = JsonUtility.FromJson<GroundPlaneLayout>(File.ReadAllText(file));
  39. tScript.layout = layout;
  40. EditorUtility.SetDirty(tScript);
  41. AssetDatabase.SaveAssets();
  42. AssetDatabase.Refresh();
  43. }
  44. }
  45. EditorGUILayout.EndHorizontal();
  46. }
  47. }
  48. }