Cleanup
This commit is contained in:
parent
85daf89041
commit
a83c4cfb3b
@ -1,7 +1,4 @@
|
||||
#if ADDRESSABLES && UI_ELEMENTS
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace NEG.Utils.UiToolkits
|
||||
{
|
||||
@ -22,5 +19,4 @@ namespace NEG.Utils.UiToolkits
|
||||
visualElement.Q<Button>("RemoveBtn").clicked += () => parent.TryRemoveItem(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1,8 +1,5 @@
|
||||
#if ADDRESSABLES && UI_ELEMENTS
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
@ -51,7 +48,6 @@ namespace NEG.Utils.UiToolkits
|
||||
}
|
||||
|
||||
private Label label;
|
||||
private AsyncOperationHandle<VisualTreeAsset> uxmlHandle, itemUxmlHandle;
|
||||
|
||||
private VisualTreeAsset itemPrefab;
|
||||
|
||||
@ -91,13 +87,11 @@ namespace NEG.Utils.UiToolkits
|
||||
string path = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets($"t:Script {nameof(MultiSelectChips)}")[0]);
|
||||
path = path.Remove(path.LastIndexOf('/'));
|
||||
|
||||
SetVisuals(AssetDatabase.LoadAssetAtPath<VisualTreeAsset>($"{path}/MultiSelectChips.uxml"));
|
||||
itemPrefab = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>($"{path}/MultiSelectChipItem.uxml");
|
||||
SetVisuals(AssetDatabase.LoadAssetAtPath<VisualTreeAsset>($"{path}/Resources/MultiSelectChips.uxml"));
|
||||
itemPrefab = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>($"{path}/Resources/MultiSelectChipItem.uxml");
|
||||
#else
|
||||
uxmlHandle = Addressables.LoadAssetAsync<VisualTreeAsset>("NegUiToolkits/MultiSelectChips.uxml");
|
||||
itemUxmlHandle = Addressables.LoadAssetAsync<VisualTreeAsset>("NegUiToolkits/MultiSelectChipItem.uxml");
|
||||
uxmlHandle.Completed += OnUxmlLoaded;
|
||||
itemUxmlHandle.Completed += OnItemUxmlLoaded;
|
||||
SetVisuals(Resources.Load<VisualTreeAsset>("MultiSelectChips.uxml"));
|
||||
itemPrefab = Resources.Load<VisualTreeAsset>("MultiSelectChipItem.uxml");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -106,7 +100,7 @@ namespace NEG.Utils.UiToolkits
|
||||
if (itemPrefab == null || itemsSource == null || realItemsParent == null)
|
||||
return;
|
||||
|
||||
List<MultiSelectChipItem> itemsToDestroy = new List<MultiSelectChipItem>(spawnedItems);
|
||||
var itemsToDestroy = new List<MultiSelectChipItem>(spawnedItems);
|
||||
|
||||
itemsToDestroy.RemoveAll((x) => itemsSource.Contains(x.ChipItem));
|
||||
|
||||
@ -132,10 +126,7 @@ namespace NEG.Utils.UiToolkits
|
||||
}
|
||||
}
|
||||
|
||||
public void TryRemoveItem(IMultiSelectChipItem item)
|
||||
{
|
||||
OnTryingToRemoveItem?.Invoke(item);
|
||||
}
|
||||
public void TryRemoveItem(IMultiSelectChipItem item) => OnTryingToRemoveItem?.Invoke(item);
|
||||
|
||||
private void InitLabel()
|
||||
{
|
||||
@ -146,35 +137,6 @@ namespace NEG.Utils.UiToolkits
|
||||
Insert(0, label);
|
||||
}
|
||||
|
||||
private void OnUxmlLoaded(AsyncOperationHandle<VisualTreeAsset> operation)
|
||||
{
|
||||
if (operation.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
SetVisuals(operation.Result);
|
||||
Addressables.Release(uxmlHandle);
|
||||
UpdateItems();
|
||||
}
|
||||
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 SetVisuals(VisualTreeAsset treeAsset)
|
||||
{
|
||||
realItemsParent = treeAsset.Instantiate();
|
||||
@ -187,5 +149,4 @@ namespace NEG.Utils.UiToolkits
|
||||
realItemsParent = button.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
8
UiToolkit/MultiSelectChips/Resources.meta
Normal file
8
UiToolkit/MultiSelectChips/Resources.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a807a09d7c00be478bf44636c2cc89f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user