Skip to content

Commit

Permalink
feat: improve ux
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarianZ committed Oct 7, 2024
1 parent 4b69767 commit f3b7c06
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 70 deletions.
87 changes: 23 additions & 64 deletions Editor/Scripts/AssetItemView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ internal class AssetItemView : VisualElement
public const string DragGenericData = "GBG_AQA_DragItem";

public AssetHandle AssetHandle { get; private set; }

private VisualElement _container;
private Image _assetIcon;
private Image _categoryIcon;
private Label _label;
private double _lastClickTime;

Expand All @@ -34,9 +35,6 @@ public AssetItemView()
// content
style.height = new Length(100, LengthUnit.Percent);
style.flexDirection = FlexDirection.Row;
style.backgroundColor = EditorGUIUtility.isProSkin
? new Color(0.35f, 0.35f, 0.35f, 0.5f)
: new Color(0.9f, 0.9f, 0.9f, 0.5f);
// margin
style.marginLeft = 0;
style.marginRight = 0;
Expand All @@ -58,6 +56,21 @@ public AssetItemView()
style.borderBottomLeftRadius = 0;
style.borderBottomRightRadius = 0;

// container
_container = new VisualElement
{
name = "Container",
style =
{
flexGrow = 1,
flexDirection = FlexDirection.Row,
backgroundColor = EditorGUIUtility.isProSkin
? new Color(0.35f, 0.35f, 0.35f, 0.5f)
: new Color(0.9f, 0.9f, 0.9f, 0.5f),
}
};
Add(_container);

_assetIcon = new Image
{
name = "AssetIcon",
Expand All @@ -69,7 +82,7 @@ public AssetItemView()
height = 24,
}
};
Add(_assetIcon);
_container.Add(_assetIcon);

_label = new Label
{
Expand All @@ -86,78 +99,49 @@ public AssetItemView()
textOverflow = TextOverflow.Ellipsis,
}
};
Add(_label);
_container.Add(_label);
}

public void Bind(AssetHandle target)
{
AssetHandle = target;
AssetHandle.Update();

//tooltip = $"{AssetHandle.GetAssetPath()} ({AssetHandle.Category})";
tooltip = AssetHandle.GetAssetPath();
_label.text = AssetHandle.GetDisplayName();

string categoryIconTooltip;
Texture assetIconTex;
Texture categoryIconTex;
switch (AssetHandle.Category)
{
case AssetCategory.ProjectAsset:
assetIconTex = GetObjectIcon(AssetHandle.Asset, null);
categoryIconTex = null;
categoryIconTooltip = null;
break;

case AssetCategory.SceneObject:
assetIconTex = GetObjectIcon(AssetHandle.Asset, AssetHandle.Scene);
categoryIconTex = GetSceneObjectTexture(true);
categoryIconTooltip = "Scene Object";
break;

case AssetCategory.ExternalFile:
string path = AssetHandle.GetAssetPath();
assetIconTex = File.Exists(path) || Directory.Exists(path)
? GetExternalFileTexture(false)
: GetWarningTexture();
categoryIconTex = GetExternalFileTexture(true);
categoryIconTooltip = "External File of Folder";
break;

case AssetCategory.Url:
assetIconTex = GetUrlTexture();
categoryIconTex = assetIconTex;
categoryIconTooltip = "URL";
break;

case AssetCategory.MenuItem:
assetIconTex = GetMenuItemTexture();
categoryIconTex = assetIconTex;
categoryIconTooltip = "MenuItem";
break;

default:
throw new ArgumentOutOfRangeException(nameof(AssetHandle.Category), AssetHandle.Category, null);
}

_assetIcon.image = assetIconTex;
if (categoryIconTex)
{
if (_categoryIcon == null)
{
CreateCategoryIcon();
}

Assert.IsTrue(_categoryIcon != null);
_categoryIcon.tooltip = categoryIconTooltip;
_categoryIcon.image = categoryIconTex;
_categoryIcon.style.display = DisplayStyle.Flex;
}
else if (_categoryIcon != null)
{
_categoryIcon.tooltip = categoryIconTooltip;
_categoryIcon.image = null;
_categoryIcon.style.display = DisplayStyle.None;
}
}

public void Unbind()
Expand All @@ -167,39 +151,14 @@ public void Unbind()
tooltip = null;
_assetIcon.image = null;
_label.text = null;
if (_categoryIcon != null)
{
_categoryIcon.tooltip = null;
_categoryIcon.image = null;
_categoryIcon.style.display = DisplayStyle.None;
}
}

private void CreateCategoryIcon()
public void SetVerticalPadding(float padding)
{
if (_categoryIcon != null)
{
return;
}

_categoryIcon = new Image
{
name = "CategoryIcon",
//pickingMode = PickingMode.Ignore, // Allow picking to show tooltip
style =
{
flexShrink = 0,
alignSelf = Align.Center,
width = 16,
height = 16,
}
};
// To avoid conflict with the drag action of the ListView items.
_categoryIcon.RegisterCallback<PointerDownEvent>(evt => evt.StopImmediatePropagation());

Add(_categoryIcon);
style.paddingTop = style.paddingBottom = padding;
}


private void OnClick()
{
if (AssetHandle.Category == AssetCategory.ExternalFile)
Expand Down
17 changes: 12 additions & 5 deletions Editor/Scripts/AssetQuickAccessWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void OnEnable()
titleContent = EditorGUIUtility.IconContent(
EditorGUIUtility.isProSkin ? "d_Favorite" : "Favorite");
titleContent.text = "Asset Quick Access";
minSize = new Vector2(330, 180);
minSize = new Vector2(260, 180);

AssemblyReloadEvents.afterAssemblyReload -= SetViewDirtyDelay;
AssemblyReloadEvents.afterAssemblyReload += SetViewDirtyDelay;
Expand Down Expand Up @@ -215,7 +215,11 @@ private void CreateGUI()
// Toolbar
Toolbar toolbar = new Toolbar
{
style = { justifyContent = Justify.SpaceBetween }
style =
{
height = StyleKeyword.Auto,
justifyContent = Justify.SpaceBetween,
}
};
rootVisualElement.Add(toolbar);

Expand All @@ -226,7 +230,11 @@ private void CreateGUI()
style = { flexShrink = 1 },
};
#if UNITY_2022_2_OR_NEWER
radioButtonGroup.Q(className: RadioButtonGroup.containerUssClassName).style.flexDirection = FlexDirection.Row;
VisualElement radioButtonGroupContainer = radioButtonGroup.Q(className: RadioButtonGroup.containerUssClassName);
radioButtonGroupContainer.style.flexDirection = FlexDirection.Row;
radioButtonGroupContainer.style.flexWrap = Wrap.Wrap;
#else
radioButtonGroup.style.flexWrap = Wrap.Wrap;
#endif
//radioButtonGroup.RegisterValueChangedCallback(SelectCategory); // Not work in Unity 2021
toolbar.Add(radioButtonGroup);
Expand Down Expand Up @@ -546,10 +554,9 @@ private VisualElement CreateNewAssetListItem()
private void BindAssetListItem(VisualElement element, int index)
{
AssetItemView view = (AssetItemView)element;
view.style.marginTop = LocalCache.SelectedCategories == AssetCategory.None ? 0 : 1;
view.style.marginBottom = LocalCache.SelectedCategories == AssetCategory.None ? 0 : 1;
AssetHandle assetHandle = (AssetHandle)_assetListView.itemsSource[index];
view.Bind(assetHandle);
view.SetVerticalPadding(LocalCache.SelectedCategories == AssetCategory.None ? 0 : 1);
}

private void UnbindAssetListItem(VisualElement element, int index)
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.0",
"version": "3.3.1",
"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 f3b7c06

Please sign in to comment.