MyGui.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public static class MpsGui
  5. {
  6. public static readonly GUILayoutOption HalfSlider = GUILayout.Width(98);
  7. public static readonly Texture2D white = Utility.MakeTex(2, 2, Color.white);
  8. public static readonly Texture2D transparentBlack = Utility.MakeTex(2, 2, new Color(0f, 0f, 0f, 0.8f));
  9. public static readonly GUIStyle SliderLabelStyle;
  10. public static readonly GUIStyle SliderStyle;
  11. public static readonly GUIStyle SliderStyleNoLabel;
  12. public static readonly GUIStyle SliderTextBoxStyle;
  13. public static readonly GUIStyle SliderThumbStyle;
  14. public static readonly GUIStyle SliderResetButtonStyle;
  15. private static readonly GUIStyle lineStyleWhite;
  16. private static readonly GUIStyle lineStyleBlack;
  17. private static readonly GUIStyle textureBoxStyle;
  18. private static readonly GUIStyle headerLabelStyle;
  19. static MpsGui()
  20. {
  21. GUI.skin = null;
  22. lineStyleWhite = new GUIStyle(GUI.skin.box)
  23. {
  24. margin = new RectOffset(0, 0, 8, 8),
  25. normal = { background = Utility.MakeTex(2, 2, new Color(1f, 1f, 1f, 0.2f)) }
  26. };
  27. lineStyleWhite.padding = lineStyleWhite.border = new RectOffset(0, 0, 1, 1);
  28. lineStyleBlack = new GUIStyle(lineStyleWhite)
  29. {
  30. normal = { background = Utility.MakeTex(2, 2, new Color(0f, 0f, 0f, 0.3f)) }
  31. };
  32. textureBoxStyle = new GUIStyle(GUI.skin.box)
  33. {
  34. normal = { background = Utility.MakeTex(2, 2, new Color(0f, 0f, 0f, 0f)) }
  35. };
  36. textureBoxStyle.padding = textureBoxStyle.margin = new RectOffset(0, 0, 0, 0);
  37. headerLabelStyle = new GUIStyle(GUI.skin.label)
  38. {
  39. padding = new RectOffset(7, 0, 0, -5),
  40. normal = { textColor = Color.white },
  41. fontSize = 14
  42. };
  43. SliderLabelStyle = new GUIStyle(GUI.skin.label)
  44. {
  45. alignment = TextAnchor.LowerLeft,
  46. fontSize = 13,
  47. normal = { textColor = Color.white }
  48. };
  49. SliderStyle = new GUIStyle(GUI.skin.horizontalSlider);
  50. SliderStyleNoLabel = new GUIStyle(SliderStyle) { margin = { top = 10 } };
  51. SliderTextBoxStyle = new GUIStyle(GUI.skin.textField) { fontSize = 12, };
  52. SliderResetButtonStyle = new GUIStyle(GUI.skin.button)
  53. {
  54. alignment = TextAnchor.MiddleRight,
  55. fontSize = 10
  56. };
  57. SliderThumbStyle = new GUIStyle(GUI.skin.horizontalSliderThumb);
  58. }
  59. private static void Line(GUIStyle style) => GUILayout.Box(GUIContent.none, style, GUILayout.Height(1));
  60. public static void WhiteLine() => Line(lineStyleWhite);
  61. public static void BlackLine() => Line(lineStyleBlack);
  62. public static void DrawTexture(Texture texture, params GUILayoutOption[] layoutOptions)
  63. {
  64. GUILayout.Box(texture, textureBoxStyle, layoutOptions);
  65. }
  66. public static int ClampFont(int size, int min, int max) => Mathf.Clamp(Utility.GetPix(size), min, max);
  67. public static void Header(string text, params GUILayoutOption[] layoutOptions)
  68. {
  69. GUILayout.Label(text, headerLabelStyle, layoutOptions);
  70. }
  71. }
  72. }