Skip to content

Commit

Permalink
feat: Optimized UI & Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarianZ committed Nov 17, 2024
1 parent 8586600 commit fc5c6af
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 78 deletions.
85 changes: 14 additions & 71 deletions Editor/Scripts/AssetItemView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public AssetItemView()
style =
{
flexShrink = 0,
width = 24,
height = 24,
alignSelf = Align.Center,
width = 16,
height = 16,
marginLeft = 4,
}
};
_container.Add(_assetIcon);
Expand Down Expand Up @@ -125,7 +127,7 @@ public void Bind(AssetHandle target)
case AssetCategory.ExternalFile:
string path = AssetHandle.GetAssetPath();
assetIconTex = File.Exists(path) || Directory.Exists(path)
? GetExternalFileTexture(false)
? GetExternalFileTexture()
: GetWarningTexture();
break;

Expand Down Expand Up @@ -301,15 +303,7 @@ private void ShowMenuItemContextMenu(Vector2 mousePosition)
}


#region Static Textures

private static Texture _sceneObjectTextureCache;
private static Texture _sceneObjectTextureSmallCache;
private static Texture _externalFileTextureCache;
private static Texture _externalFileTextureSmallCache;
private static Texture _urlTextureCache;
private static Texture _menuItemTextureCache;
private static Texture _warningTextureCache;
#region Get Textures

private static Texture GetObjectIcon(UObject obj, SceneAsset containingScene)
{
Expand All @@ -330,86 +324,35 @@ private static Texture GetObjectIcon(UObject obj, SceneAsset containingScene)
}
}

return GetSceneObjectTexture(false);
return GetSceneObjectTexture();
}

return GetWarningTexture();
}

private static Texture GetSceneObjectTexture(bool small)
private static Texture GetSceneObjectTexture()
{
if (small)
{
if (!_sceneObjectTextureSmallCache)
{
_sceneObjectTextureSmallCache = (Texture)EditorGUIUtility.Load(
EditorGUIUtility.isProSkin
? "d_UnityEditor.SceneHierarchyWindow"
: "UnityEditor.SceneHierarchyWindow");
}

return _sceneObjectTextureSmallCache;
}

if (!_sceneObjectTextureCache)
{
_sceneObjectTextureCache = (Texture)EditorGUIUtility.Load(
EditorGUIUtility.isProSkin
? "d_UnityEditor.SceneHierarchyWindow@2x"
: "UnityEditor.SceneHierarchyWindow@2x");
}

return _sceneObjectTextureCache;
return EditorGUIUtility.IconContent("UnityEditor.SceneHierarchyWindow").image;
}

private static Texture GetExternalFileTexture(bool small)
private static Texture GetExternalFileTexture()
{
if (small)
{
if (!_externalFileTextureSmallCache)
{
_externalFileTextureSmallCache = (Texture)EditorGUIUtility.Load(EditorGUIUtility.isProSkin ? "d_Import" : "Import");
}

return _externalFileTextureSmallCache;
}

if (!_externalFileTextureCache)
{
_externalFileTextureCache = (Texture)EditorGUIUtility.Load(EditorGUIUtility.isProSkin ? "d_Import@2x" : "Import@2x");
}

return _externalFileTextureCache;
return EditorGUIUtility.IconContent("Import").image;
}

private static Texture GetUrlTexture()
{
if (!_urlTextureCache)
{
_urlTextureCache = (Texture)EditorGUIUtility.Load(EditorGUIUtility.isProSkin ? "d_BuildSettings.Web.Small" : "BuildSettings.Web.Small");
}

return _urlTextureCache;
return EditorGUIUtility.IconContent("BuildSettings.Web.Small").image;
}

private static Texture GetMenuItemTexture()
{
if (!_menuItemTextureCache)
{
_menuItemTextureCache = (Texture)EditorGUIUtility.Load(EditorGUIUtility.isProSkin ? "d_PlayButton@2x" : "PlayButton@2x");
}

return _menuItemTextureCache;
return EditorGUIUtility.IconContent("PlayButton").image;
}

private static Texture GetWarningTexture()
{
if (!_warningTextureCache)
{
_warningTextureCache = (Texture)EditorGUIUtility.Load("Warning@2x");
}

return _warningTextureCache;
return EditorGUIUtility.IconContent("Warning").image;
}

#endregion
Expand Down
5 changes: 2 additions & 3 deletions Editor/Scripts/AssetQuickAccessWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ private void OnEnable()
{
_instance = this;

titleContent = EditorGUIUtility.IconContent(
EditorGUIUtility.isProSkin ? "d_Favorite" : "Favorite");
titleContent = EditorGUIUtility.IconContent("Favorite");
titleContent.text = "Asset Quick Access";
minSize = new Vector2(260, 180);

Expand Down Expand Up @@ -198,7 +197,7 @@ private void OnFocus()

private void ShowButton(Rect pos)
{
if (GUI.Button(pos, EditorGUIUtility.IconContent("_Help"), GUI.skin.FindStyle("IconButton")))
if (GUI.Button(pos, EditorGUIUtility.IconContent("_Help"), EditorStyles.iconButton))
{
Application.OpenURL("https://github.com/SolarianZ/UnityAssetQuickAccessTool");
}
Expand Down
4 changes: 3 additions & 1 deletion Editor/Scripts/UrlEditWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ private static Color GetTextColor(bool isErrorText)
return new Color32(200, 0, 0, 255);
}

return EditorGUIUtility.isProSkin ? new Color32(196, 196, 196, 255) : new Color32(24, 24, 24, 255);
return EditorGUIUtility.isProSkin
? new Color32(196, 196, 196, 255)
: new Color32(24, 24, 24, 255);
}

//public static async Task<string> GetWebsiteTitleAsync(string url)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Pin frequently used **Unity objects, menu items and external files/folders/urls*

Unity 2021.3 and later.

For Unity 2019.2 - Unity 2021.2, please use version [v1.4.1](https://github.com/SolarianZ/UnityAssetQuickAccessTool/releases/tag/v1.4.1).
For Unity 2019.2 - Unity 2021.2, please use version [v1.4.2](https://github.com/SolarianZ/UnityAssetQuickAccessTool/releases/tag/v1.4.2).<br/>
For Unity 2017.4 - Unity 2019.1, please use version [v1.2.1](https://github.com/SolarianZ/UnityAssetQuickAccessTool/releases/tag/v1.2.1).

## Installation
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

Unity 2021.3 或更新版本。

Unity 2019.2 - Unity 2021.2请使用 [v1.4.1](https://github.com/SolarianZ/UnityAssetQuickAccessTool/releases/tag/v1.4.1) 版本。
Unity 2019.2 - Unity 2021.2请使用 [v1.4.2](https://github.com/SolarianZ/UnityAssetQuickAccessTool/releases/tag/v1.4.2) 版本。<br/>
Unity 2017.4 - Unity 2019.1请使用 [v1.2.1](https://github.com/SolarianZ/UnityAssetQuickAccessTool/releases/tag/v1.2.1) 版本。

## 安装
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.greenbamboogames.assetquickaccess",
"version": "3.3.1",
"version": "3.3.2",
"displayName": "Asset Quick Access!",
"description": "Pin frequently used objects to a separate editor window. An enhanced version of Unity's Favorites feature.",
"unity": "2021.3",
Expand Down

0 comments on commit fc5c6af

Please sign in to comment.