using System.Collections.Generic; using UnityEditor; using UnityEngine; using System.IO; [InitializeOnLoad] public class XSFurUIStyles : MonoBehaviour { public static string ver = "2.0.0"; public static class Styles { public static GUIContent version = new GUIContent("XSToon v" + ver, "The currently installed version of XSToon."); } // Labels public static void DoHeader(GUIContent HeaderText) { GUILayout.Label(HeaderText, new GUIStyle(EditorStyles.boldLabel) { alignment = TextAnchor.MiddleCenter, wordWrap = true, fontSize = 12 }); } public static void doLabel(string text) { GUILayout.Label(text, new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleCenter, wordWrap = true, fontSize = 12 }); } public static void doLabelLeft(string text) { GUILayout.Label(text, new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleLeft, wordWrap = true, fontSize = 12 }); } public static void doLabelSmall(string text) { GUILayout.Label(text, new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleLeft, wordWrap = true, fontSize = 10 }); } // ---- static public GUIStyle _LineStyle; static public GUIStyle LineStyle { get { if (_LineStyle == null) { _LineStyle = new GUIStyle(); _LineStyle.normal.background = EditorGUIUtility.whiteTexture; _LineStyle.stretchWidth = true; } return _LineStyle; } } //Help Box public static void HelpBox(string message, MessageType type) { EditorGUILayout.HelpBox(message, type); } //GUI Lines static public void Separator() { GUILayout.Space(4); GUILine(new Color(.3f, .3f, .3f), 1); GUILine(new Color(.9f, .9f, .9f), 1); GUILayout.Space(4); } static public void SeparatorThin() { GUILayout.Space(2); GUILine(new Color(.1f, .1f, .1f), 1f); GUILine(new Color(.3f, .3f, .3f), 1f); GUILayout.Space(2); } static public void SeparatorBig() { GUILayout.Space(10); GUILine(new Color(.3f, .3f, .3f), 2); GUILayout.Space(1); GUILine(new Color(.3f, .3f, .3f), 2); GUILine(new Color(.85f, .85f, .85f), 1); GUILayout.Space(10); } static public void GUILine(float height = 2f) { GUILine(Color.black, height); } static public void GUILine(Color color, float height = 2f) { Rect position = GUILayoutUtility.GetRect(0f, float.MaxValue, height, height, LineStyle); if (Event.current.type == EventType.Repaint) { Color orgColor = GUI.color; GUI.color = orgColor * color; LineStyle.Draw(position, false, false, false, false); GUI.color = orgColor; } } // -------------- //Find Asset Path public static string findAssetPath(string finalFilePath) { string[] guids1 = AssetDatabase.FindAssets("XSUpdater", null); string untouchedString = AssetDatabase.GUIDToAssetPath(guids1[0]); string[] splitString = untouchedString.Split('/'); ArrayUtility.RemoveAt(ref splitString, splitString.Length - 1); ArrayUtility.RemoveAt(ref splitString, splitString.Length - 1); finalFilePath = string.Join("/", splitString); return finalFilePath; } private static Rect DrawShuriken(string title, Vector2 contentOffset, int HeaderHeight) { var style = new GUIStyle("ShurikenModuleTitle"); style.font = new GUIStyle(EditorStyles.boldLabel).font; style.border = new RectOffset(15, 7, 4, 4); style.fixedHeight = HeaderHeight; style.contentOffset = contentOffset; var rect = GUILayoutUtility.GetRect(16f, HeaderHeight, style); GUI.Box(rect, title, style); return rect; } private static Rect DrawShurikenCenteredTitle(string title, Vector2 contentOffset, int HeaderHeight) { var style = new GUIStyle("ShurikenModuleTitle"); style.font = new GUIStyle(EditorStyles.boldLabel).font; style.border = new RectOffset(15, 7, 4, 4); style.fixedHeight = HeaderHeight; style.contentOffset = contentOffset; style.alignment = TextAnchor.MiddleCenter; var rect = GUILayoutUtility.GetRect(16f, HeaderHeight, style); GUI.Box(rect, title, style); return rect; } public static bool ShurikenFoldout(string title, bool display) { var rect = DrawShuriken(title, new Vector2(20f, -2f), 22); var e = Event.current; var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f); if (e.type == EventType.Repaint) { EditorStyles.foldout.Draw(toggleRect, false, false, display, false); } if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition)) { display = !display; e.Use(); } return display; } public static void ShurikenHeader(string title) { DrawShuriken(title, new Vector2(6f, -2f), 22); } public static void ShurikenHeaderCentered(string title) { DrawShurikenCenteredTitle(title, new Vector2(0f, -2f), 22); } public static void constrainedShaderProperty(MaterialEditor materialEditor, MaterialProperty prop, GUIContent style, int tabSize) { EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(30)); materialEditor.ShaderProperty(prop, style, tabSize); EditorGUILayout.EndHorizontal(); } //exrta buttons public static void githubButton(int Width, int Height) { if (GUILayout.Button("Github", GUILayout.Width(Width), GUILayout.Height(Height))) { Application.OpenURL("https://github.com/Xiexe"); } } public static void discordButton(int Width, int Height) { if (GUILayout.Button("Discord", GUILayout.Width(Width), GUILayout.Height(Height))) { Application.OpenURL("https://discord.gg/3JDeUTw"); } } public static void patreonButton(int Width, int Height) { if (GUILayout.Button("Patreon", GUILayout.Width(Width), GUILayout.Height(Height))) { Application.OpenURL("https://www.patreon.com/xiexe"); } } public static void DoFooter() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); discordButton(70, 30); patreonButton(70, 30); githubButton(70, 30); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } public static bool HelpBoxWithButton(GUIContent messageContent, GUIContent buttonContent) { const float kButtonWidth = 60f; const float kSpacing = 5f; const float kButtonHeight = 20f; // Reserve size of wrapped text Rect contentRect = GUILayoutUtility.GetRect(messageContent, EditorStyles.helpBox); // Reserve size of button GUILayoutUtility.GetRect(1, kButtonHeight + kSpacing); // Render background box with text at full height contentRect.height += kButtonHeight + kSpacing; GUI.Label(contentRect, messageContent, EditorStyles.helpBox); // Button (align lower right) Rect buttonRect = new Rect(contentRect.xMax - kButtonWidth - 4f, contentRect.yMax - kButtonHeight - 4f, kButtonWidth, kButtonHeight); return GUI.Button(buttonRect, buttonContent); } }