-
-
Notifications
You must be signed in to change notification settings - Fork 150
Open
Description
using UnityEngine;
using UnityEngine.UIElements;
using R3;
using TMPro;
using System;
public class UITest : MonoBehaviour
{
[SerializeField] UIDocument uiDocument;
VisualElement uiRoot;
[SerializeField] TextMeshProUGUI label;
ReactiveProperty<int> clickCount = new(0);
private void Start()
{
uiRoot = uiDocument.rootVisualElement;
var buttons = uiRoot.Query<Button>().ToList();
foreach (var button in buttons)
{
var clickStream = Observable.FromEvent((action) => button.clicked += action, (action) => button.clicked -= action, destroyCancellationToken);
clickStream.Subscribe(_ =>
{
clickCount.Value++;
});
}
// Issue occurs here:
clickCount.ThrottleLast(TimeSpan.FromSeconds(1)) //---> When using ThrottleFirst, text changes are displayed correctly
//.ObserveOnCurrentSynchronizationContext() //---> When this method is added, text changes are displayed correctly
.Subscribe(x => {
label.text = $"Click Count: {x}"; //===> When using ThrottleLast, label.text changes are visible in the inspector, but not updated in the Game View. Why?
});
label.text = "111"; // this is correctly
}
}
unity 6000.2.10f1
Metadata
Metadata
Assignees
Labels
No labels