From 9bb0c1611c31d059ba4615ca1229bfd59136d115 Mon Sep 17 00:00:00 2001 From: HoSHIZA <58137717+HoSHIZA@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:41:46 +0300 Subject: [PATCH] Fix incorrect display of textures during manual installation in Assets directory (#99) --- Editor/TriEditorStyles.cs | 65 +++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/Editor/TriEditorStyles.cs b/Editor/TriEditorStyles.cs index 14af4e8..471f6b4 100644 --- a/Editor/TriEditorStyles.cs +++ b/Editor/TriEditorStyles.cs @@ -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) { - border = new RectOffset(2, 2, 2, 2), - normal = + _contentBox = new GUIStyle(FallbackContentBox); + } + else + { + _contentBox = new GUIStyle { - background = LoadTexture("TriInspector_Content_Bg"), - }, - }; + normal = + { + background = backgroundTexture, + }, + }; + } + + _contentBox.border = new RectOffset(2, 2, 2, 2); } return _contentBox; @@ -41,14 +52,24 @@ namespace TriInspector { 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; @@ -57,10 +78,14 @@ namespace TriInspector 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); } }