LuxURP_HelpBtn.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using System.Collections;
  3. #if UNITY_EDITOR
  4. using UnityEditor;
  5. #endif
  6. namespace LuxURPEssentials
  7. {
  8. public class LuxURP_HelpBtn : PropertyAttribute
  9. {
  10. public string URL;
  11. public LuxURP_HelpBtn(string URL) {
  12. this.URL = URL;
  13. }
  14. }
  15. #if UNITY_EDITOR
  16. [CustomPropertyDrawer(typeof(LuxURP_HelpBtn))]
  17. public class LuxURP_HelpBtnDrawer : DecoratorDrawer {
  18. private static string baseURL = "https://docs.google.com/document/d/1ck3hmPzKUdewHfwsvmPYwSPCP8azwtpzN7aOLJHvMqE/edit#heading=";
  19. LuxURP_HelpBtn help {
  20. get { return ((LuxURP_HelpBtn)attribute); }
  21. }
  22. override public void OnGUI(Rect position) {
  23. float brightness = 1.45f;
  24. if (!EditorGUIUtility.isProSkin) {
  25. brightness = 1.0f;
  26. }
  27. Color helpCol = new Color(0.32f * brightness, 0.50f * brightness, 1.0f * brightness, 1.0f * brightness);
  28. GUIStyle myMiniHelpBtn = new GUIStyle(EditorStyles.miniButton);
  29. myMiniHelpBtn.padding = new RectOffset(0, 0, 2, 2);
  30. myMiniHelpBtn.normal.background = null;
  31. myMiniHelpBtn.normal.textColor = helpCol;
  32. myMiniHelpBtn.onNormal.textColor = helpCol;
  33. myMiniHelpBtn.active.textColor = helpCol;
  34. myMiniHelpBtn.onActive.textColor = helpCol;
  35. myMiniHelpBtn.focused.textColor = helpCol;
  36. myMiniHelpBtn.onFocused.textColor = helpCol;
  37. position.x = position.x + position.width - 36;
  38. position.y += 8;
  39. position.width = 36;
  40. if (GUI.Button(position, "Help", myMiniHelpBtn)) {
  41. Application.OpenURL(baseURL + help.URL);
  42. }
  43. }
  44. }
  45. #endif
  46. }