Add multiSelectChips
This commit is contained in:
parent
92cbe3dd8c
commit
8fd0b58639
8
UiToolkit.meta
Normal file
8
UiToolkit.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c452ac88625d6c46a12fb35375d8019
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
UiToolkit/MultiSelectChips.meta
Normal file
8
UiToolkit/MultiSelectChips.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1091fdb6a84af3488e7772b53a5f875
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
UiToolkit/MultiSelectChips/MultiSelectChips.cs
Normal file
128
UiToolkit/MultiSelectChips/MultiSelectChips.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
|
||||
public class MultiSelectChips : VisualElement
|
||||
{
|
||||
public string LabelText
|
||||
{
|
||||
get => label.text;
|
||||
set
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
if (label == null)
|
||||
{
|
||||
InitLabel();
|
||||
}
|
||||
|
||||
label.text = value;
|
||||
}
|
||||
else if (label != null)
|
||||
{
|
||||
label.RemoveFromHierarchy();
|
||||
label = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IList ItemsSource
|
||||
{
|
||||
get => itemsSource;
|
||||
|
||||
set
|
||||
{
|
||||
itemsSource = value;
|
||||
UpdateItems();
|
||||
}
|
||||
}
|
||||
|
||||
private Label label;
|
||||
private AsyncOperationHandle<VisualTreeAsset> uxmlHandle, itemUxmlHandle;
|
||||
|
||||
private VisualTreeAsset itemPrefab;
|
||||
|
||||
private IList itemsSource;
|
||||
|
||||
public new class UxmlFactory : UxmlFactory<MultiSelectChips, UxmlTraits>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public new class UxmlTraits : VisualElement.UxmlTraits
|
||||
{
|
||||
private readonly UxmlStringAttributeDescription label;
|
||||
|
||||
public UxmlTraits()
|
||||
{
|
||||
label = new()
|
||||
{
|
||||
name = "label"
|
||||
};
|
||||
}
|
||||
|
||||
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
|
||||
{
|
||||
base.Init(ve, bag, cc);
|
||||
((MultiSelectChips)ve).LabelText = label.GetValueFromBag(bag, cc);
|
||||
}
|
||||
}
|
||||
|
||||
public MultiSelectChips() : base()
|
||||
{
|
||||
uxmlHandle = Addressables.LoadAssetAsync<VisualTreeAsset>("NegUiToolkits/MultiSelectChips.uxml");
|
||||
itemUxmlHandle = Addressables.LoadAssetAsync<VisualTreeAsset>("NegUiToolkits/MultiSelectChipsItem.uxml");
|
||||
uxmlHandle.Completed += OnUxmlLoaded;
|
||||
itemUxmlHandle.Completed += OnItemUxmlLoaded;
|
||||
}
|
||||
|
||||
public void UpdateItems()
|
||||
{
|
||||
if (itemPrefab == null)
|
||||
return;
|
||||
}
|
||||
|
||||
private void InitLabel()
|
||||
{
|
||||
label = new Label()
|
||||
{
|
||||
pickingMode = PickingMode.Ignore
|
||||
};
|
||||
Add(label);
|
||||
}
|
||||
|
||||
private void OnUxmlLoaded(AsyncOperationHandle<VisualTreeAsset> operation)
|
||||
{
|
||||
if (operation.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Add(operation.Result.Instantiate());
|
||||
Addressables.Release(uxmlHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Asset failed to load.");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnItemUxmlLoaded(AsyncOperationHandle<VisualTreeAsset> operation)
|
||||
{
|
||||
|
||||
if (operation.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
itemPrefab = operation.Result;
|
||||
Addressables.Release(itemUxmlHandle);
|
||||
UpdateItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Asset failed to load.");
|
||||
}
|
||||
}
|
||||
|
||||
private void
|
||||
|
||||
}
|
||||
11
UiToolkit/MultiSelectChips/MultiSelectChips.cs.meta
Normal file
11
UiToolkit/MultiSelectChips/MultiSelectChips.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bbcd96ba00647146aac6667496c426d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6
UiToolkit/MultiSelectChips/MultiSelectChips.uxml
Normal file
6
UiToolkit/MultiSelectChips/MultiSelectChips.uxml
Normal file
@ -0,0 +1,6 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<ui:ListView focusable="true" show-add-remove-footer="false" horizontal-scrolling="true" />
|
||||
<ui:VisualElement style="flex-direction: row; flex-wrap: wrap;">
|
||||
<ui:Button text="+" display-tooltip-when-elided="true" name="AddItem" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
10
UiToolkit/MultiSelectChips/MultiSelectChips.uxml.meta
Normal file
10
UiToolkit/MultiSelectChips/MultiSelectChips.uxml.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28ecbe3f92afaca4faeec3e9fb3af6a2
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
Loading…
x
Reference in New Issue
Block a user