using System; using System.Collections; using System.Collections.Generic; using BITFALL.Cosmetic; using BITKit; using BITKit.IO; using BITKit.UX; using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.UIElements; using YooAsset; namespace BITFALL.UX { public class UXCosmetics : MonoBehaviour { [SerializeReference,SubclassSelector] private ICosmeticService _cosmeticService; [SerializeField] private VisualTreeAsset cosmeticsTemplate; [UXBindPath("cosmetics-container")] private VisualElement _cosmeticsContainer; private void Start() { BITKit.UX.UXUtils.Inject(this); _cosmeticsContainer.Clear(); _cosmeticService.OnCosmeticsChanged += Rebuild; Rebuild(); } private async void Rebuild() { _cosmeticsContainer.Clear(); foreach (var cosmetic in _cosmeticService.Cosmetics) { var assetHandle = YooAssets.LoadAssetAsync(cosmetic.AddressablePath); await assetHandle; if(destroyCancellationToken.IsCancellationRequested) return; var so = assetHandle.AssetObject.As(); var instance =new UXContainer(_cosmeticsContainer.Create(cosmeticsTemplate)) ; instance.icon.style.backgroundImage = new StyleBackground(so.Icon); instance.contextLabel.text = so.name; } } } }