EditorGUIUtility.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Diagnostics;
  5. using Object = UnityEngine.Object;
  6. public static class NREditorUtility
  7. {
  8. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  9. public static void BoolField(Object target, string name, ref bool member, ref bool modified)
  10. {
  11. BoolField(target, new GUIContent(name), ref member, ref modified);
  12. }
  13. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  14. public static void BoolField(Object target, GUIContent name, ref bool member, ref bool modified)
  15. {
  16. EditorGUI.BeginChangeCheck();
  17. bool value = EditorGUILayout.Toggle(name, member);
  18. if (EditorGUI.EndChangeCheck())
  19. {
  20. Undo.RecordObject(target, "Changed " + name);
  21. member = value;
  22. modified = true;
  23. }
  24. }
  25. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  26. public static void Popup(Object target, string name, ref Enum select, ref bool modified)
  27. {
  28. Popup(target, new GUIContent(name), ref select, ref modified);
  29. }
  30. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  31. public static void Popup(Object target, GUIContent name, ref Enum select, ref bool modified)
  32. {
  33. EditorGUI.BeginChangeCheck();
  34. var value = EditorGUILayout.EnumPopup(name, select);
  35. if (EditorGUI.EndChangeCheck())
  36. {
  37. Undo.RecordObject(target, "Changed " + name);
  38. select = value;
  39. modified = true;
  40. }
  41. }
  42. }