Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect display of textures during manual installation in Assets directory #99

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions Editor/TriEditorStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,41 @@ namespace TriInspector
{
public static class TriEditorStyles
{
private const string BaseResourcesPath = "Packages/com.codewriter.triinspector/Editor/Resources/";

private static GUIStyle _contentBox;
private static GUIStyle _box;

public static GUIStyle TabOnlyOne { get; } = "Tab onlyOne";
public static GUIStyle TabFirst { get; } = "Tab first";
public static GUIStyle TabMiddle { get; } = "Tab middle";
public static GUIStyle TabLast { get; } = "Tab last";


private static GUIStyle FallbackContentBox { get; } = "HelpBox";
private static GUIStyle FallbackBox { get; } = "HelpBox";

public static GUIStyle ContentBox
{
get
{
if (_contentBox == null)
{
_contentBox = new GUIStyle
var backgroundTexture = LoadTexture("TriInspector_Content_Bg");

if (backgroundTexture == null)
{
_contentBox = new GUIStyle(FallbackContentBox);
}
else
{
border = new RectOffset(2, 2, 2, 2),
normal =
_contentBox = new GUIStyle
{
background = LoadTexture("TriInspector_Content_Bg"),
},
};
normal =
{
background = backgroundTexture,
},
};
}

_contentBox.border = new RectOffset(2, 2, 2, 2);
}

return _contentBox;
Expand All @@ -41,14 +52,24 @@ public static GUIStyle Box
{
if (_box == null)
{
_box = new GUIStyle
var backgroundTexture = LoadTexture("TriInspector_Box_Bg");

if (backgroundTexture == null)
{
border = new RectOffset(2, 2, 2, 2),
normal =
_box = new GUIStyle(FallbackBox);
}
else
{
_box = new GUIStyle
{
background = LoadTexture("TriInspector_Box_Bg"),
},
};
normal =
{
background = backgroundTexture,
},
};
}

_box.border = new RectOffset(2, 2, 2, 2);
}

return _box;
Expand All @@ -57,10 +78,14 @@ public static GUIStyle Box

private static Texture2D LoadTexture(string name)
{
var path = EditorGUIUtility.isProSkin
? BaseResourcesPath + name + "_Dark.png"
: BaseResourcesPath + name + ".png";

name = EditorGUIUtility.isProSkin ? $"{name}_Dark" : name;

var results = AssetDatabase.FindAssets($"{name} t:texture2D");

if (results.Length == 0) return null;

var path = AssetDatabase.GUIDToAssetPath(results[0]);

return (Texture2D) EditorGUIUtility.Load(path);
}
}
Expand Down