Unity/UniRx/値変更検知/配列数
提供: 初心者エンジニアの簡易メモ
2023年6月25日 (日) 15:48時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「<pre> using System.Collections; using System.Collections.Generic; using UnityEngine; using UniRx; using System; public class ChangeValueListCountScene : MonoBehaviour {...」)
using System.Collections; using System.Collections.Generic; using UnityEngine; using UniRx; using System; public class ChangeValueListCountScene : MonoBehaviour { class RequestData { public string Url; public bool IsCompleted; } class SampleClient { List<RequestData> requestDatas; public List<RequestData> RequestDatas { get => requestDatas; set => requestDatas = value; } public SampleClient() { requestDatas = new List<RequestData>(); requestDatas.Add(new RequestData { Url = "ttp://example.com", IsCompleted = false, }); requestDatas.Add(new RequestData { Url = "ttp://example2.com", IsCompleted = false, }); } public void Add() { requestDatas.Add(new RequestData { Url = "ttp://example3.com", IsCompleted = false, }); } } void Start() { var sampleClient = new SampleClient(); sampleClient.RequestDatas.ObserveEveryValueChanged(_ => _.Count) .Subscribe(count => { Debug.Log("count=" + count); }).AddTo(gameObject); // 5秒後に遅延実行 Observable.Timer(System.TimeSpan.FromSeconds(5)) .Subscribe(_ => { sampleClient.Add(); }).AddTo(gameObject); } }