PanelEditor.cs 885 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace HQFPSWeapons.UserInterface
  4. {
  5. [CustomEditor(typeof(Panel))]
  6. public class PanelEditor : UnityEditor.Editor
  7. {
  8. public override void OnInspectorGUI()
  9. {
  10. base.OnInspectorGUI();
  11. EditorGUILayout.Space();
  12. Rect rect = EditorGUILayout.GetControlRect();
  13. float fullWidth = rect.width;
  14. float btnWidth = rect.width * 0.35f;
  15. rect.x = fullWidth * 0.25f - btnWidth / 2;
  16. rect.width = btnWidth;
  17. var canvasGroup = serializedObject.FindProperty("m_CanvasGroup").objectReferenceValue as CanvasGroup;
  18. if(GUI.Button(rect, "Show") && canvasGroup != null)
  19. {
  20. canvasGroup.alpha = 1f;
  21. canvasGroup.blocksRaycasts = true;
  22. }
  23. rect.x = fullWidth * 0.75f - btnWidth / 2;
  24. if(GUI.Button(rect, "Hide") && canvasGroup != null)
  25. {
  26. canvasGroup.alpha = 0f;
  27. canvasGroup.blocksRaycasts = false;
  28. }
  29. }
  30. }
  31. }