标签:btn server observer onclick current oid scroll print initial
1 public Button btn0; 2 public Button btn1; 3 public Button btn2; 4 public Button btn3; 5 public Button btn4; 6 private Subject<int> _currentBtn = new Subject<int>(); 7 8 void InitializeItem(int index){ 9 OnShowItem(index); 10 } 11 12 void OnShowItem(int index){ 13 _currentBtn.OnNext(index); 14 } 15 16 public IObservable<int> ShowInfoItem(){ 17 return _currentBtn.onClickAsObservable(); 18 }
1 private InfoListView view = new InfoListView(); 2 3 public void Initialize(){ 4 view.ShowInfoItem().Subscribe(onNext: x=>{ 5 print(x); 6 } 7 8 }
Subject同时充当了Observer和Observable的角色
1 public Text text; 2 public Slider slider; 3 public Button btn; 4 public ScrollRect scroll; 5 6 void Start(){ 7 slider.OnValueChangedAsObservable().Where(x => x > 0.5f). 8 SubscribeToText(ReturnText(),x =>((int)(slider.value * 100)) 9 .ToString()); 10 11 btn.OnClickAsObservable().SubscribeToText(ReturnText(), 12 x => btn.gameObject.transform.GetChild(0). 13 GetComponent<Text>().text); 14 15 scroll.OnScrollAsObservable().SubscribeToText(ReturnText(), 16 x => x.ToString()); 17 } 18 19 Text ReturnText(){ 20 return text; 21 }
1 public Toggle toggle; 2 public Button btn; 3 4 void Start(){ 5 toggle.OnValueChangedAsObservable().SubscribeToInteractable(btn); 6 }
toggle是一个勾选选项,当toggle被勾选时,btn可以使用;当toggle不被勾选时,btn不起作用
标签:btn server observer onclick current oid scroll print initial
原文地址:http://www.cnblogs.com/yeting-home/p/6363066.html