EditorGUILayout.Toggle()

作者:追风剑情 发布于:2019-5-7 11:47 分类:Unity3d

示例

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5.  
  6. public class GUIStyleWindow : EditorWindow
  7. {
  8. private bool group = true;
  9. private bool A = true;
  10. private bool B = false;
  11. private bool C = true;
  12. private bool D = false;
  13. private bool E = false;
  14.  
  15. void OnGUI()
  16. {
  17. group = EditorGUILayout.BeginToggleGroup("Toggle Group", group);
  18. //复选按钮风格
  19. A = EditorGUILayout.ToggleLeft("Select A", A);
  20. B = EditorGUILayout.ToggleLeft("Select B", B);
  21.  
  22. GUILayout.Space(10);
  23.  
  24. //单选按钮风格
  25. // EditorStyles只会影响右侧风格
  26. EditorGUI.BeginChangeCheck();
  27. C = EditorGUILayout.Toggle("Select C", C, EditorStyles.radioButton);
  28. if (EditorGUI.EndChangeCheck())
  29. {
  30. if (C) D = E = false;
  31. else C = true;
  32. }
  33.  
  34. EditorGUI.BeginChangeCheck();
  35. D = EditorGUILayout.Toggle("Select D", D, EditorStyles.radioButton);
  36. if (EditorGUI.EndChangeCheck())
  37. {
  38. if (D) C = E = false;
  39. else D = true;
  40. }
  41.  
  42. EditorGUI.BeginChangeCheck();
  43. E = EditorGUILayout.Toggle("Select E", E, EditorStyles.radioButton);
  44. if (EditorGUI.EndChangeCheck())
  45. {
  46. if (E) C = D = false;
  47. else E = true;
  48. }
  49. EditorGUILayout.EndToggleGroup();
  50. }
  51.  
  52. [MenuItem("MyWindow/ToggleGroup")]
  53. static void ShowWindow()
  54. {
  55. var window = GetWindow<GUIStyleWindow>();
  56. window.titleContent = new GUIContent("My Window");
  57. window.Show();
  58. }
  59. }

效果

11111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号