MyGui.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. private static readonly GUIStyle lineStyleWhite;
  10. private static readonly GUIStyle lineStyleBlack;
  11. private static readonly GUIStyle textureBoxStyle;
  12. static MpsGui()
  13. {
  14. lineStyleWhite = new GUIStyle(GUI.skin.box);
  15. lineStyleWhite.padding = lineStyleWhite.border = new RectOffset(0, 0, 1, 1);
  16. lineStyleWhite.margin = new RectOffset(0, 0, 8, 8);
  17. lineStyleWhite.normal.background = Utility.MakeTex(2, 2, new Color(1f, 1f, 1f, 0.2f));
  18. lineStyleBlack = new GUIStyle(lineStyleWhite);
  19. lineStyleBlack.normal.background = Utility.MakeTex(2, 2, new Color(0f, 0f, 0f, 0.3f));
  20. textureBoxStyle = new GUIStyle(GUI.skin.box);
  21. textureBoxStyle.normal.background = Utility.MakeTex(2, 2, new Color(0f, 0f, 0f, 0f));
  22. textureBoxStyle.padding = textureBoxStyle.margin = new RectOffset(0, 0, 0, 0);
  23. }
  24. private static void Line(GUIStyle style) => GUILayout.Box(GUIContent.none, style, GUILayout.Height(1));
  25. public static void WhiteLine() => Line(lineStyleWhite);
  26. public static void BlackLine() => Line(lineStyleBlack);
  27. public static void DrawTexture(Texture texture, params GUILayoutOption[] layoutOptions)
  28. {
  29. GUILayout.Box(texture, textureBoxStyle, layoutOptions);
  30. }
  31. public static int ClampFont(int size, int min, int max) => Mathf.Clamp(Utility.GetPix(size), min, max);
  32. public static void Header(string text, params GUILayoutOption[] layoutOptions)
  33. {
  34. GUIStyle style = new GUIStyle(GUI.skin.label) { padding = new RectOffset(7, 0, 0, -5) };
  35. GUILayout.Label(text, style, layoutOptions);
  36. }
  37. }
  38. }