DrawWindowBanner.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. using Boxophobic.Constants;
  5. namespace Boxophobic.StyledGUI
  6. {
  7. public partial class StyledGUI
  8. {
  9. public static void DrawWindowBanner(Color bannerColor, string bannerText, string helpURL)
  10. {
  11. GUILayout.Space(15);
  12. var bannerFullRect = GUILayoutUtility.GetRect(0, 0, 36, 0);
  13. var bannerBeginRect = new Rect(bannerFullRect.position.x + 20, bannerFullRect.position.y, 20, 36);
  14. var bannerMiddleRect = new Rect(bannerFullRect.position.x + 40, bannerFullRect.position.y, bannerFullRect.xMax - 75, 36);
  15. var bannerEndRect = new Rect(bannerFullRect.xMax - 36, bannerFullRect.position.y, 20, 36);
  16. var iconRect = new Rect(bannerFullRect.xMax - 51, bannerFullRect.position.y + 5, 30, 26);
  17. Color guiColor;
  18. if (EditorGUIUtility.isProSkin)
  19. {
  20. bannerColor = new Color(bannerColor.r, bannerColor.g, bannerColor.b, 1f);
  21. }
  22. else
  23. {
  24. bannerColor = CONSTANT.ColorLightGray;
  25. }
  26. if (bannerColor.r + bannerColor.g + bannerColor.b <= 1.5)
  27. {
  28. guiColor = CONSTANT.ColorLightGray;
  29. }
  30. else
  31. {
  32. guiColor = CONSTANT.ColorDarkGray;
  33. }
  34. GUI.color = bannerColor;
  35. GUI.DrawTexture(bannerBeginRect, CONSTANT.BannerImageBegin, ScaleMode.StretchToFill, true);
  36. GUI.DrawTexture(bannerMiddleRect, CONSTANT.BannerImageMiddle, ScaleMode.StretchToFill, true);
  37. GUI.DrawTexture(bannerEndRect, CONSTANT.BannerImageEnd, ScaleMode.StretchToFill, true);
  38. GUI.color = guiColor;
  39. #if UNITY_2019_3_OR_NEWER
  40. GUI.Label(bannerFullRect, "<size=16><color=#" + ColorUtility.ToHtmlStringRGB(guiColor) + ">" + bannerText + "</color></size>", CONSTANT.TitleStyle);
  41. #else
  42. GUI.Label(bannerFullRect, "<size=14><color=#" + ColorUtility.ToHtmlStringRGB(guiColor) + "><b>" + bannerText + "</b></color></size>", CONSTANT.TitleStyle);
  43. #endif
  44. if (GUI.Button(iconRect, CONSTANT.IconHelp, new GUIStyle { alignment = TextAnchor.MiddleCenter }))
  45. {
  46. Application.OpenURL(helpURL);
  47. }
  48. GUI.color = Color.white;
  49. GUILayout.Space(15);
  50. }
  51. }
  52. }