Hi, I started using Ui Toolkit and bindings for all UI to have fewer constraints from code, but it does not seem performant.
I have around 100 elements in ScrollView. Each element has its own ViewData which implements IDataSourceViewHashProvider, INotifyBindablePropertyChanged to ensure no bindings updates are made.
Changing binding-mode from ToTarget to ToTargetOnce changes nothing.
Is there something I can do to reduce ShouldUpdateBindings cost?
Here is like my ViewData code look like for those elements
public class BindableProperty : IDataSourceViewHashProvider, INotifyBindablePropertyChanged
{
private long viewVersion;
public long GetViewHashCode()
{
return viewVersion;
}
public void Publish()
{
viewVersion++;
}
public event EventHandler<BindablePropertyChangedEventArgs> propertyChanged;
protected void Notify([CallerMemberName] string property = "")
{
propertyChanged?.Invoke(this, new BindablePropertyChangedEventArgs(property));
}
}
public class ItemGridViewData : BindableProperty
{
public string itemId;
public string level;
public DisplayStyle notification;
public Sprite itemSprite;
public Sprite heroSprite;
public ItemRarity rarity;
public Sprite rarityFrameSprite;
public DisplayStyle locked;
public DisplayStyle wholePanelLockedDisplayStyle;
public DisplayStyle wholePanelUnlockedDisplayStyle;
public DisplayStyle displayStyle;
public void SetData(
ItemInstanceData item,
HeroInstanceData equippedBy,
ItemRarityConverter itemRarityConverter,
bool wholePanelLocked = false)
{
displayStyle = item != null ? DisplayStyle.Flex : DisplayStyle.None;
if (item == null)
{
itemId = null;
Publish();
return;
}
itemId = item.id;
wholePanelLockedDisplayStyle = wholePanelLocked ? DisplayStyle.Flex : DisplayStyle.None;
wholePanelUnlockedDisplayStyle = !wholePanelLocked ? DisplayStyle.Flex : DisplayStyle.None;
level = $"Lvl {item.level + 1}";
//TODO: display notification when?
notification = DisplayStyle.None;
itemSprite = Game.AssetsService.ItemsAssetsScriptableObject.GetItemSprite(item.GetBaseItemId());
heroSprite = equippedBy != null ? Game.VisualEntityData.GetEntityData(equippedBy.id).mainSprite : null;
rarity = item.rarity;
rarityFrameSprite = itemRarityConverter.ConvertEnumToSprite(item.rarity);
locked = item.locked ? DisplayStyle.Flex : DisplayStyle.None;
Publish();
}
}