Skip to content

Commit

Permalink
Fixed application of styles when using Unity Pro Skin ( Dark Skin ) E…
Browse files Browse the repository at this point in the history
…ditor

Addressing issues #1, #2
Switched from Application.HasProLicense() to EditorGUIUtility.isProSkin to detect when dark skin gui is in use.
Various small fixes to GuiStyles and usage to make light mode look better.
  • Loading branch information
noisecrime committed Apr 13, 2023
1 parent f2f3a76 commit 3bc2d9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,13 @@ public static class EditorGUIStyles

public static GUIStyle scopeDark;
public static GUIStyle scopeLight;
public static GUIStyle scopeStd;

public static Color errorColor = new Color( 0.5f, 0f, 0f );
public static Color warningColor = Color.yellow;
public static Color normalColor = Color.white;
public static Color disabledColor = Color.gray;
public static GUIStyle scopeStd;

public static Color colorContentNormal = Color.white;
public static Color colorContentError = new Color( 0.5f, 0f, 0f );
public static Color colorContentWarning = Color.yellow;
public static Color colorContentGreen = Color.green;
public static Color colorContentWarning = IsUsingDarkSkinMode ? Color.yellow : new Color( 0.6f, 0.4f, 0.0f );
public static Color colorContentGreen = IsUsingDarkSkinMode ? Color.green : new Color( 0.0f, 0.6f, 0.0f );
public static Color colorTextNormal = IsUsingDarkSkinMode ? Color.white : Color.black;

// How to destroy these?
public static Texture2D backgroundTxDark;
Expand All @@ -62,15 +58,23 @@ public static class EditorGUIStyles

// GUISkin skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);

/// <summary>
/// Single access point to check for use of 'DarkSkin/ProSkin' use in Unity Editor.
/// </summary>
/// <remarks>
/// Switched from Application.HasProLicense() to EditorGUIUtility.isProSkin to fix issues with GUI Styles.
/// Enables easier testing.
/// Force this to return true if you want dark skin mode regardless.
/// </remarks>
public static bool IsUsingDarkSkinMode { get { return EditorGUIUtility.isProSkin; } }


static EditorGUIStyles()
{
bool hasProLicense = Application.HasProLicense();

// Textures
backgroundTxDark = EditorGUIMethods.CreateTexture( 8, 8, hasProLicense ? new Color32( 48, 48, 48, 255 ) : new Color32( 154, 154, 154, 255 ) );
backgroundTxLight = EditorGUIMethods.CreateTexture( 8, 8, hasProLicense ? new Color32( 64, 64, 64, 255 ) : new Color32( 193, 193, 193, 255 ) );
backgroundTxStd = EditorGUIMethods.CreateTexture( 8, 8, hasProLicense ? new Color32( 56, 56, 56, 255 ) : new Color32( 162, 162, 162, 255 ) );
backgroundTxDark = EditorGUIMethods.CreateTexture( 8, 8, IsUsingDarkSkinMode ? new Color32( 48, 48, 48, 255 ) : new Color32( 154, 154, 154, 255 ) );
backgroundTxLight = EditorGUIMethods.CreateTexture( 8, 8, IsUsingDarkSkinMode ? new Color32( 64, 64, 64, 255 ) : new Color32( 193, 193, 193, 255 ) );
backgroundTxStd = EditorGUIMethods.CreateTexture( 8, 8, IsUsingDarkSkinMode ? new Color32( 56, 56, 56, 255 ) : new Color32( 162, 162, 162, 255 ) );
// backgroundTextureSelect = IMGUIMethods.CreateTexture(8,8, new Color32(56,56,156,255));

RectOffset margin = new RectOffset(0,0,0,0);
Expand Down Expand Up @@ -127,7 +131,7 @@ static void DefineStyle( ref GUIStyle style, GUIStyle from, FontStyle font, Text
/// <param name="iconNameFormat">'{0}ic_file_download_{1}_18dp_1x.png'</param>
public static void CreateIconContent( ref Texture iconTexture, ref GUIContent iconContent, string materialIconsPath, string iconNameFormat, string contentText )
{
string iconColor = Application.HasProLicense() ? "white" : "black";
string iconColor = "white"; // IsUsingDarkSkinMode ? "white" : "black";

if ( null == iconTexture )
iconTexture = ( Texture )AssetDatabase.LoadAssetAtPath( string.Format( iconNameFormat, materialIconsPath, iconColor ), typeof( Texture ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,12 @@ private void GuiStorePackageItem( AssetPackage ap, GUIStyle scope )
GUILayout.Space( 4f );

// Column Entries
GUI.contentColor = ap.isUnityStandardAsset ? EditorGUIStyles.colorContentWarning : EditorGUIStyles.colorTextNormal;
GuiCustomMenu ( ap, EditorGUIStyles.labelNormLeft, columnWidths[ 0 ] );
GUI.contentColor = ap.isArchived ? EditorGUIStyles.colorContentGreen : EditorGUIStyles.colorContentNormal;
EditorGUILayout.LabelField( ap.isArchived ? iconCheckContent : iconCancelContent, iconLabelStyle, GUILayout.Height( lineHeight ), GUILayout.Width( columnWidths[ 8 ] ) );
GUILayout.Space( 12f );
GUI.contentColor = ap.isUnityStandardAsset ? EditorGUIStyles.colorContentWarning : EditorGUIStyles.colorContentNormal;
GUI.contentColor = ap.isUnityStandardAsset ? EditorGUIStyles.colorContentWarning : EditorGUIStyles.colorTextNormal;
GuiCustomLabel( ap.version, EditorGUIStyles.labelNormLeft, columnWidths[ 3 ] );
GuiCustomLabel( ap.unity_version, EditorGUIStyles.labelNormLeft, columnWidths[ 1 ] );
GuiCustomLabel( ap.displayFileSize, EditorGUIStyles.labelNormRight, columnWidths[ 2 ] );
Expand Down

0 comments on commit 3bc2d9c

Please sign in to comment.