using System; using System.Reflection; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; namespace TweenAnimation { internal class TweenModuleGUIStyles { private delegate bool GetBoldDefaultFontFunc(); private static GetBoldDefaultFontFunc GetBoldDefaultFont; static Texture2D m_BgTexture; static Texture2D m_BgTextureActive; static Texture2D m_BgTextureWire; static Texture2D m_BgTextureWireSmall; static Texture2D LoadTexture(string path) { return AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D; } static TweenModuleGUIStyles() { Type editorGUIUtility = typeof(EditorGUIUtility); GetBoldDefaultFont = (GetBoldDefaultFontFunc)GetMethod(typeof(GetBoldDefaultFontFunc), typeof(EditorGUIUtility), "GetBoldDefaultFont", BindingFlags.Static | BindingFlags.NonPublic); m_BgTexture = LoadTexture(TweenAnimationSetup.root + "Icons/Background.png"); m_BgTextureActive = LoadTexture(TweenAnimationSetup.root + "Icons/BackgroundActive.png"); m_BgTextureWire = LoadTexture(TweenAnimationSetup.root + "Icons/BackgroundWire.png"); m_BgTextureWireSmall = LoadTexture(TweenAnimationSetup.root + "Icons/BackgroundWireSmall.png"); } private static Delegate GetMethod(Type del, Type type, string name, BindingFlags flag) { var method = type.GetMethod(name, flag); Delegate deleg = Delegate.CreateDelegate(del, method); return deleg; } public GUIStyle label { get { return GetBoldDefaultFont() ? this.m_LabelBold : this.m_Label; } } public GUIStyle editableLabel { get { return GetBoldDefaultFont() ? this.m_EditableLabelBold : this.m_EditableLabel; } } public GUIStyle objectField { get { return GetBoldDefaultFont() ? this.m_ObjectFieldBold : this.m_ObjectField; } } public GUIStyle numberField { get { return GetBoldDefaultFont() ? this.m_NumberFieldBold : this.m_NumberField; } } public GUIStyle moduleHeaderStyle { get { return GetBoldDefaultFont() ? this.m_ModuleHeaderStyleBold : this.m_ModuleHeaderStyle; } } public GUIStyle popup { get { return GetBoldDefaultFont() ? this.m_PopupStyleBold : this.m_PopupStyle; } } public GUIStyle emitterHeaderStyle { get { return this.m_EmitterHeaderStyle; } } public GUIStyle effectBgStyle { get { return this.m_EffectBgStyle; } } public GUIStyle moduleBgStyle { get { return this.m_ModuleBgStyle; } } public GUIStyle plus { get { return this.m_Plus; } } public GUIStyle minus { get { return this.m_Minus; } } public GUIStyle checkmark { get { return this.m_Checkmark; } } public GUIStyle checkmarkMixed { get { return this.m_CheckmarkMixed; } } public GUIStyle minMaxCurveStateDropDown { get { return this.m_MinMaxCurveStateDropDown; } } public GUIStyle toggle { get { return this.m_Toggle; } } public GUIStyle toggleMixed { get { return this.m_ToggleMixed; } } public GUIStyle selectionMarker { get { return this.m_SelectionMarker; } } public GUIStyle toolbarButtonLeftAlignText { get { return this.m_ToolbarButtonLeftAlignText; } } public GUIStyle modulePadding { get { return this.m_ModulePadding; } } public GUIStyle customDataWindow { get { return this.m_CustomDataWindow; } } public Texture2D warningIcon { get { return this.m_WarningIcon; } } public GUIStyle floatfiled { get { return m_FloatField; } } public GUIStyle headerBg { get { return m_HeaderBg; } } private GUIStyle m_Label; private GUIStyle m_LabelBold; private GUIStyle m_EditableLabel; private GUIStyle m_EditableLabelBold; private GUIStyle m_ObjectField; private GUIStyle m_ObjectFieldBold; private GUIStyle m_NumberField; private GUIStyle m_NumberFieldBold; private GUIStyle m_ModuleHeaderStyle; private GUIStyle m_ModuleHeaderStyleBold; private GUIStyle m_PopupStyle; private GUIStyle m_PopupStyleBold; private GUIStyle m_EmitterHeaderStyle; private GUIStyle m_EffectBgStyle; private GUIStyle m_ModuleBgStyle; private GUIStyle m_Plus; private GUIStyle m_Minus; private GUIStyle m_Checkmark; private GUIStyle m_CheckmarkMixed; private GUIStyle m_MinMaxCurveStateDropDown; private GUIStyle m_Toggle; private GUIStyle m_ToggleMixed; private GUIStyle m_SelectionMarker; private GUIStyle m_ToolbarButtonLeftAlignText; private GUIStyle m_ModulePadding; private GUIStyle m_CustomDataWindow; private GUIStyle m_FloatField; private Texture2D m_WarningIcon; private static TweenModuleGUIStyles s_TweenModuleGUIStyles; private GUIStyle m_HeaderBg; private GUIStyle m_HeaderTitle; public GUIStyle headerTitle { get { return m_HeaderTitle; } } private GUIStyle m_Bg; public GUIStyle bg { get { return m_Bg; } } private GUIStyle m_BgSmall; public GUIStyle bgSmall { get { return m_BgSmall; } } private GUIStyle m_AddNewModule; public GUIStyle addNewModule { get { return m_AddNewModule; } } private GUIStyle m_Text; public GUIStyle text { get { return m_Text; } } public static TweenModuleGUIStyles Get() { bool flag = s_TweenModuleGUIStyles == null; if (flag) { s_TweenModuleGUIStyles = new TweenModuleGUIStyles(); } return s_TweenModuleGUIStyles; } private TweenModuleGUIStyles() { InitStyle(out this.m_Label, out this.m_LabelBold, "ShurikenLabel"); InitStyle(out this.m_EditableLabel, out this.m_EditableLabelBold, "ShurikenEditableLabel"); InitStyle(out this.m_ObjectField, out this.m_ObjectFieldBold, "ShurikenObjectField"); InitStyle(out this.m_NumberField, out this.m_NumberFieldBold, "ShurikenValue"); InitStyle(out this.m_ModuleHeaderStyle, out this.m_ModuleHeaderStyleBold, "ShurikenModuleTitle"); InitStyle(out this.m_PopupStyle, out this.m_PopupStyleBold, "ShurikenPopUp"); InitStyle(out this.m_EmitterHeaderStyle, "ShurikenEmitterTitle"); InitStyle(out this.m_EmitterHeaderStyle, "ShurikenEmitterTitle"); InitStyle(out this.m_EffectBgStyle, "ShurikenEffectBg"); InitStyle(out this.m_ModuleBgStyle, "ShurikenModuleBg"); InitStyle(out this.m_Plus, "OL Plus"); InitStyle(out this.m_Minus, "OL Minus"); InitStyle(out this.m_Checkmark, "ShurikenCheckMark"); InitStyle(out this.m_CheckmarkMixed, "ShurikenCheckMarkMixed"); InitStyle(out this.m_MinMaxCurveStateDropDown, "ShurikenDropdown"); InitStyle(out this.m_Toggle, "ShurikenToggle"); InitStyle(out this.m_ToggleMixed, "ShurikenToggleMixed"); InitStyle(out this.m_SelectionMarker, "IN ThumbnailShadow"); InitStyle(out this.m_ToolbarButtonLeftAlignText, "ToolbarButton"); this.m_CustomDataWindow = new GUIStyle(GUI.skin.window); this.m_CustomDataWindow.font = EditorStyles.miniFont; this.m_EmitterHeaderStyle.clipping = TextClipping.Clip; this.m_EmitterHeaderStyle.padding.right = 45; this.m_ToolbarButtonLeftAlignText = new GUIStyle(this.m_ToolbarButtonLeftAlignText); this.m_ToolbarButtonLeftAlignText.alignment = TextAnchor.MiddleLeft; this.m_ModulePadding = new GUIStyle(); this.m_ModulePadding.padding = new RectOffset(3, 3, 4, 2); InitStyle(out m_FloatField, EditorStyles.numberField, s => s.fontSize = 9); InitStyle(out m_HeaderBg, s => { s.border = new RectOffset(11, 15, 10, 15); s.normal.background = m_BgTexture; s.active.background = m_BgTextureActive; s.hover.background = m_BgTexture; }); InitStyle(out m_HeaderTitle, s => { s.fontStyle = FontStyle.Bold; s.fontSize = 9; }); InitStyle(out m_Bg, s => { s.border = new RectOffset(5, 5, 5, 5); s.normal.background = m_BgTextureWire; }); InitStyle(out m_BgSmall, s => { s.border = new RectOffset(3, 3, 3, 3); s.normal.background = m_BgTextureWireSmall; }); InitStyle(out m_AddNewModule,EditorStyles.miniButtonMid , s => { s.fontSize = 9; }); InitStyle(out m_Text, EditorStyles.label, s => { s.fontSize = 9; }); } private static void InitStyle(out GUIStyle normal, string name) { normal = FindStyle(name); } private delegate void Initter(GUIStyle style); private static void InitStyle(out GUIStyle normal, GUIStyle other, Initter initter) { normal = new GUIStyle(other); initter(normal); } private static void InitStyle(out GUIStyle normal, Initter initter) { normal = new GUIStyle(); initter(normal); } private static void InitStyle(out GUIStyle normal, out GUIStyle bold, string name) { InitStyle(out normal, name); bold = new GUIStyle(normal); bold.font = EditorStyles.miniBoldFont; } private static GUIStyle FindStyle(string styleName) { return styleName; } } }