public void Text(UniRx.IObservable <string> text) { var g = gObject; var sub = text.Subscribe((str) => { g.text = str; }); uiBase.AddDisposable(sub); }
//[UIAttributes.UIBindPropertyInfo("name")] public void Name(UniRx.IObservable <string> o) { var g = gObject; var sub = o.Subscribe((str) => { g.name = str; }); uiBase.AddDisposable(sub); }
public void Color(UniRx.IObservable <UnityEngine.Color> color) { var g = gObject; var sub = color.Subscribe((c) => { g.titleColor = c; }); uiBase.AddDisposable(sub); }
public void Visible(UniRx.IObservable <bool> o) { var g = gObject; var sub = o.Subscribe((b) => { g.visible = b; }); uiBase.AddDisposable(sub); }
public void Text(UniRx.IObservable <string> text, bool BindToInputTextField = false, bool BindToRichTextField = false) { var g = gObject; var sub = text.Subscribe((str) => { str = string.IsNullOrEmpty(str) ? string.Empty : str; if (BindToInputTextField) { g.text = str; } else if (BindToRichTextField) { g.asRichTextField.text = str; } else { g.text = str; } }); uiBase.AddDisposable(sub); }
//public void ObserverAdd<T, T1>(UniRx.IReadOnlyReactiveCollection<T1> list) where T : UIBase //{ // var g = gObject; // var sub = list.ObserveAdd().Subscribe((add) => // { // var item = System.Activator.CreateInstance(typeof(T), add.Value, g) as UIBase; // }); // uiBase.AddDisposable(sub); //} /// <summary> /// 绑定列表控件和数据 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="T1"></typeparam> /// <param name="list"></param> public void ObserverListAll <T, T1>(UniRx.IReactiveCollection <T1> list, bool autoWidth = false) where T : UIBase where T1 : IViewModel { System.Type type = typeof(T); bool isImpleIViewModelCtrl = typeof(T1).IsSubclassOf(typeof(IViewModelCtrl)); var g = gObject; var u = uiBase; var observeAdd = list.ObserveAdd(); var subAdd = observeAdd.Subscribe((o) => { if (isImpleIViewModelCtrl) { type = (o.Value as IViewModelCtrl).CtrlType; } var ctrl = System.Activator.CreateInstance(type, g, o.Value) as T; ctrl.SetMainViewModel(o.Value as IViewModel); ctrl.CreateUIInstance(false); //g.AddSelection(g.numItems, true); u.TempKv[o.Value] = ctrl; if (autoWidth) { adjustWidth(ctrl, g); } ctrl.AddToPanel(u); }); var it = list.GetEnumerator(); while (it.MoveNext()) { if (isImpleIViewModelCtrl) { type = (it.Current as IViewModelCtrl).CtrlType; } var ctrl = System.Activator.CreateInstance(type, g, it.Current) as T; ctrl.SetMainViewModel(it.Current as IViewModel); ctrl.CreateUIInstance(false); //g.AddSelection(g.numItems, true); u.TempKv[it.Current] = ctrl; if (autoWidth) { adjustWidth(ctrl, g); } ctrl.AddToPanel(uiBase); } uiBase.AddDisposable(subAdd); var subRemove = list.ObserveRemove().Subscribe((o) => { Debug.Log("$$ will remove item..."); var item = g.GetChildAt(o.Index); #if _CREATE_LISTITEM_FROMPOOL_ g.RemoveChildToPoolAt(o.Index); #else g.RemoveChildAt(o.Index, true); //item.RemoveFromParent(); //item.Dispose(); if (u.TempKv.ContainsKey(o.Value)) { var uiBase1 = u.TempKv[o.Value] as UIBase; uiBase1.Close(); u.TempKv.Remove(o.Value); if (autoWidth) { adjustWidth(uiBase1, g); } } #endif }); uiBase.AddDisposable(subRemove); //TODO Maybe bug try:g.container.GetChildAt var subMove = list.ObserveMove().Subscribe((o) => { //var child = g.GetChildAt(o.OldIndex); //g.SetChildIndex(child, o.NewIndex); g.SwapChildrenAt(o.OldIndex, o.NewIndex); }); var subReset = list.ObserveReset().Subscribe((unit) => { #if _CREATE_LISTITEM_FROMPOOL_ g.RemoveChildrenToPool(); #else g.RemoveChildren(); foreach (var o in u.TempKv) { if (o.Key is T1 && list.Contains((T1)o.Key)) { var uiBase1 = o.Value as UIBase; if (uiBase1 != null) { uiBase1.Close(); } } } //u.TempKv.Clear(); #endif }); uiBase.AddDisposable(subMove); }