SampleSettingsEditor.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Samples
  4. {
  5. /// <summary>
  6. /// Simple custom editor used to show how to enable custom UI for XR Management
  7. /// configuraton data.
  8. /// </summary>
  9. [CustomEditor(typeof(SampleSettings))]
  10. public class SampleSettingsEditor : Editor
  11. {
  12. static string k_RequiresProperty = "m_RequiresItem";
  13. static string k_RuntimeToggleProperty = "m_RuntimeToggle";
  14. static GUIContent k_ShowBuildSettingsLabel = new GUIContent("Build Settings");
  15. static GUIContent k_RequiresLabel = new GUIContent("Item Requirement");
  16. static GUIContent k_ShowRuntimeSettingsLabel = new GUIContent("Runtime Settings");
  17. static GUIContent k_RuntimeToggleLabel = new GUIContent("Should I stay or should I go?");
  18. bool m_ShowBuildSettings = true;
  19. bool m_ShowRuntimeSettings = true;
  20. SerializedProperty m_RequiesItemProperty;
  21. SerializedProperty m_RuntimeToggleProperty;
  22. /// <summary>Override of Editor callback.</summary>
  23. public override void OnInspectorGUI()
  24. {
  25. if (serializedObject == null || serializedObject.targetObject == null)
  26. return;
  27. if (m_RequiesItemProperty == null) m_RequiesItemProperty = serializedObject.FindProperty(k_RequiresProperty);
  28. if (m_RuntimeToggleProperty == null) m_RuntimeToggleProperty = serializedObject.FindProperty(k_RuntimeToggleProperty);
  29. serializedObject.Update();
  30. m_ShowBuildSettings = EditorGUILayout.Foldout(m_ShowBuildSettings, k_ShowBuildSettingsLabel);
  31. if (m_ShowBuildSettings)
  32. {
  33. EditorGUI.indentLevel++;
  34. EditorGUILayout.PropertyField(m_RequiesItemProperty, k_RequiresLabel);
  35. EditorGUI.indentLevel--;
  36. }
  37. EditorGUILayout.Space();
  38. m_ShowRuntimeSettings = EditorGUILayout.Foldout(m_ShowRuntimeSettings, k_ShowRuntimeSettingsLabel);
  39. if (m_ShowRuntimeSettings)
  40. {
  41. EditorGUI.indentLevel++;
  42. EditorGUILayout.PropertyField(m_RuntimeToggleProperty, k_RuntimeToggleLabel);
  43. EditorGUI.indentLevel--;
  44. }
  45. serializedObject.ApplyModifiedProperties();
  46. }
  47. }
  48. }