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

This commit is contained in:
HoSHIZA 2023-04-09 19:41:46 +03:00 committed by GitHub
parent 42413a7a68
commit 9bb0c1611c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,30 +5,41 @@ namespace TriInspector
{ {
public static class TriEditorStyles public static class TriEditorStyles
{ {
private const string BaseResourcesPath = "Packages/com.codewriter.triinspector/Editor/Resources/";
private static GUIStyle _contentBox; private static GUIStyle _contentBox;
private static GUIStyle _box; private static GUIStyle _box;
public static GUIStyle TabOnlyOne { get; } = "Tab onlyOne"; public static GUIStyle TabOnlyOne { get; } = "Tab onlyOne";
public static GUIStyle TabFirst { get; } = "Tab first"; public static GUIStyle TabFirst { get; } = "Tab first";
public static GUIStyle TabMiddle { get; } = "Tab middle"; public static GUIStyle TabMiddle { get; } = "Tab middle";
public static GUIStyle TabLast { get; } = "Tab last"; public static GUIStyle TabLast { get; } = "Tab last";
private static GUIStyle FallbackContentBox { get; } = "HelpBox";
private static GUIStyle FallbackBox { get; } = "HelpBox";
public static GUIStyle ContentBox public static GUIStyle ContentBox
{ {
get get
{ {
if (_contentBox == null) if (_contentBox == null)
{ {
_contentBox = new GUIStyle var backgroundTexture = LoadTexture("TriInspector_Content_Bg");
if (backgroundTexture == null)
{ {
border = new RectOffset(2, 2, 2, 2), _contentBox = new GUIStyle(FallbackContentBox);
normal = }
else
{
_contentBox = new GUIStyle
{ {
background = LoadTexture("TriInspector_Content_Bg"), normal =
}, {
}; background = backgroundTexture,
},
};
}
_contentBox.border = new RectOffset(2, 2, 2, 2);
} }
return _contentBox; return _contentBox;
@ -41,14 +52,24 @@ namespace TriInspector
{ {
if (_box == null) if (_box == null)
{ {
_box = new GUIStyle var backgroundTexture = LoadTexture("TriInspector_Box_Bg");
if (backgroundTexture == null)
{ {
border = new RectOffset(2, 2, 2, 2), _box = new GUIStyle(FallbackBox);
normal = }
else
{
_box = new GUIStyle
{ {
background = LoadTexture("TriInspector_Box_Bg"), normal =
}, {
}; background = backgroundTexture,
},
};
}
_box.border = new RectOffset(2, 2, 2, 2);
} }
return _box; return _box;
@ -57,10 +78,14 @@ namespace TriInspector
private static Texture2D LoadTexture(string name) private static Texture2D LoadTexture(string name)
{ {
var path = EditorGUIUtility.isProSkin name = EditorGUIUtility.isProSkin ? $"{name}_Dark" : name;
? BaseResourcesPath + name + "_Dark.png"
: BaseResourcesPath + name + ".png"; var results = AssetDatabase.FindAssets($"{name} t:texture2D");
if (results.Length == 0) return null;
var path = AssetDatabase.GUIDToAssetPath(results[0]);
return (Texture2D) EditorGUIUtility.Load(path); return (Texture2D) EditorGUIUtility.Load(path);
} }
} }