private void DrawComponent(ILegoComponent component) { var uiRxModel = ScRxModel.GetRxModel(component.ScrollViewId); if (uiRxModel == null) { #if DEBUG string name = null; if (component.UIRect != null) { name = component.UIRect.name; } Debug.LogError("DrawComponent错误,uiRxModel为null: " + name + " " + component.ScrollViewId); #endif return; } LegoBinder.Binding(component, componentMeta, uiRxModel); component.SetRxModel(uiRxModel); if (uiRxModel.SonComponentModels.Count != 0) { foreach (var sonComponent in component.SonComponentDict) { var bigId = sonComponent.Key; var lowerId = "";//YuBigAssetIdMap.GetLowerId(bigId); LegoUIMeta sonComponentMeta = metaHelper.GetMeta(lowerId); IYuLegoUIRxModel sonComponentRxModel = uiRxModel.SonComponentModels[bigId]; LegoBinder.Binding(sonComponent.Value, sonComponentMeta, sonComponentRxModel); sonComponent.Value.SetRxModel(sonComponentRxModel); } } onDrawComponent?.Invoke(component, uiRxModel); }
private void BindSonComponentRxmodl(IYuLegoUIRxModel rxModel, ILegoUI component) { foreach (var sonComponent in component.SonComponentDict) { rxModel.SonComponentModels.Add(sonComponent.Key, sonComponent.Value.RxModel); } }
/// <summary> /// 移除数据模型 /// </summary> /// <param name="index"></param> /// <param name="rxModel"></param> private void OnRxModelRemove(int index, IYuLegoUIRxModel rxModel) { var last = components.Last; ViewModule.Restore(last.Value); components.RemoveLast(); ReDrawAllComponents(); UpdateMaxIndexOffset(); UpadteContentSize(); }
private void BindingInputField(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { var binder = binderDict[typeof(YuLegoInputField)]; var oldModel = ui.RxModel.GetControlRxModel <YuLegoInputFieldRxModel>(id); binder.UnBinding(oldModel); var inputField = ui.GetControl <YuLegoInputField>(id); var model = uiRxModel.GetControlRxModel <YuLegoInputFieldRxModel>(id); binder.Binding(inputField, model, rectMeta); }
private void BindingProgressbar(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { var binder = binderDict[typeof(YuLegoProgressbar)]; var oldModel = ui.RxModel.GetControlRxModel <YuLegoProgressbarRxModel>(id); binder.UnBinding(oldModel); var progressbar = ui.GetControl <YuLegoProgressbar>(id); var model = uiRxModel.GetControlRxModel <YuLegoProgressbarRxModel>(id); binder.Binding(progressbar, model, rectMeta); }
private void BindingPlaneToggle(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { var binder = binderDict[typeof(YuLegoPlaneToggle)]; var oldModel = ui.RxModel.GetControlRxModel <YuLegoPlaneToggleRxModel>(id); binder.UnBinding(oldModel); var planeToggle = ui.GetControl <YuLegoPlaneToggle>(id); var model = uiRxModel.GetControlRxModel <YuLegoPlaneToggleRxModel>(id); binder.Binding(planeToggle, model, rectMeta); }
private void BindingTButton(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { var binder = binderDict[typeof(YuLegoTButton)]; var oldModel = ui.RxModel.GetControlRxModel <YuLegoTButtonRxModel>(id); binder.UnBinding(oldModel); var button = ui.GetControl <YuLegoTButton>(id); var model = uiRxModel.GetControlRxModel <YuLegoTButtonRxModel>(id); binder.Binding(button, model, rectMeta); }
private void BindingRawImage(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { var binder = binderDict[typeof(YuLegoRawImage)]; var oldModel = ui.RxModel.GetControlRxModel <YuLegoRawImageRxModel>(id); binder.UnBinding(oldModel); var rawImage = ui.GetControl <YuLegoRawImage>(id); var model = uiRxModel.GetControlRxModel <YuLegoRawImageRxModel>(id); binder.Binding(rawImage, model, rectMeta); }
public IYuLegoUIRxModel AddRxModel(IYuLegoUIRxModel rxModel) { #if DEBUG if (uiRxModels.Contains(rxModel)) { throw new Exception("尝试添加一个已存在的数据模型实例!"); } #endif uiRxModels.Add(rxModel); onAdd?.Invoke(rxModel); return(rxModel); }
public void CopyRxModel(int index, IYuLegoUIRxModel targetRxModel) { if (UiRxModels.Count <= index) { #if DEBUG Debug.Log("没有足够的数据模型可以执行拷贝操作,索引已超出当前数据模型最大数量!"); #endif return; } var sourceRxModel = UiRxModels[index]; sourceRxModel.Copy(targetRxModel); }
public IYuLegoUIRxModel AddRxModel(IYuLegoUIRxModel rxModel) { var t = (T)rxModel; if (!UiRxModels.Contains(t)) { IsReplacingRxModel = true; UiRxModels.Add(t); onAdd(t); } return(t); }
private void BindingText(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { var binder = binderDict[typeof(YuLegoText)]; var oldModel = ui.RxModel.GetControlRxModel <YuLegoTextRxModel>(id); binder.UnBinding(oldModel); var text = ui.GetControl <YuLegoText>(id); var model = uiRxModel.GetControlRxModel <YuLegoTextRxModel>(id); binder.Binding(text, model, rectMeta); }
public void InsertModel(int index, IYuLegoUIRxModel rxModel) { #if DEBUG if (index < 0 || index == UiRxModels.Count - 1) { Debug.LogError($"滚动视图的数据模型插入索引超出范围,期望索引是{index}," + $"允许范围为0=>{UiRxModels.Count - 1}!"); return; } #endif UiRxModels.Insert(index, (T)rxModel); onInsert?.Invoke(index, rxModel); }
public void Copy(IYuLegoUIRxModel target) { var leftRxModels = BaseModels.Values.ToList(); var rightRxModels = target.BaseModels.Values.ToList(); if (leftRxModels.Count != rightRxModels.Count) { throw new Exception("两个数据模型实例容量不相等的UI数据模型实例无法进行复制操作!"); } var length = leftRxModels.Count; for (int i = 0; i < length; i++) { var left = (IYuLegoControlRxModel)leftRxModels[i]; var right = rightRxModels[i]; left.Copy(right); } }
private void BindingImage(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { var binder = binderDict[typeof(YuLegoImage)]; var oldModel = ui.RxModel.GetControlRxModel <YuLegoImageRxModel>(id); if (oldModel != null) { binder.UnBinding(oldModel); } #if DEBUG else { string uiName = null; if (ui?.UIRect != null) { uiName = ui.UIRect.name; } Debug.LogError("BindingImage错误,oldModel为null" + uiName + " " + id); } #endif var image = ui.GetControl <YuLegoImage>(id); var model = uiRxModel.GetControlRxModel <YuLegoImageRxModel>(id); if (model != null) { binder.Binding(image, model, rectMeta); } #if DEBUG else { string uiName = null; if (ui?.UIRect != null) { uiName = ui.UIRect.name; } Debug.LogError("BindingImage错误,Model为null" + uiName + " " + id); } #endif }
public void Binding(ILegoUI ui, LegoUIMeta uiMeta, IYuLegoUIRxModel uiRxModel) { var rectMetas = uiMeta.RectMetas; var elementTypes = uiMeta.ElementTypes; var length = rectMetas.Count; for (var i = 0; i < length; i++) { var id = rectMetas[i].Name; var elementType = elementTypes[i]; var rectMeta = rectMetas[i]; try { BingdngAtElementType(elementType, ui, id, uiRxModel, rectMeta); } catch (Exception e) { Debug.LogError($"在绑定类型为{elementType}Id为{id}的目标控件时发生异常,异常信息为{e.Message + e.StackTrace}!"); } } }
/// <summary> /// 插入数据模型 /// </summary> /// <param name="index"></param> /// <param name="rxModel"></param> private void OnRxModelInsert(int index, IYuLegoUIRxModel rxModel) { TryRequestBuildComponent(); }
/// <summary> /// 添加数据模型 /// </summary> /// <param name="rxModel"></param> private void OnRxModelAdd(IYuLegoUIRxModel rxModel) { TryRequestBuildComponent(); UpadteContentSize(); onComponentRxModelAdd?.Invoke(rxModel); }
public void SetRxModel(IYuLegoUIRxModel rxModel) { RxModel = rxModel; RxModel.MapUI = this; }
private void SetViewSonComponentRxModel(IYuLegoUIRxModel rxModel, ILegoUI component) { rxModel.InitRxModel(); component.SetRxModel(rxModel); }
/// <summary> /// 绑定数据模型与脚本 /// </summary> /// <param name="rxModel"></param> /// <param name="view"></param> private void SetViewRxModel(IYuLegoUIRxModel rxModel, ILegoUI view) { rxModel.InitRxModel(); view.SetRxModel(rxModel); }
private void BingdngAtElementType(LegoUIType elementType, ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel, LegoRectTransformMeta rectMeta) { switch (elementType) { case LegoUIType.Text: BindingText(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Image: BindingImage(ui, id, uiRxModel, rectMeta); break; case LegoUIType.RawImage: BindingRawImage(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Button: BindingButton(ui, id, uiRxModel, rectMeta); break; case LegoUIType.TButton: BindingTButton(ui, id, uiRxModel, rectMeta); break; case LegoUIType.InputField: BindingInputField(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Slider: BindingSlider(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Progressbar: BindingProgressbar(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Toggle: BindingToggle(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Tab: break; case LegoUIType.Dropdown: BindingDropdown(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Rocker: break; case LegoUIType.Grid: break; case LegoUIType.ScrollView: break; case LegoUIType.None: break; case LegoUIType.InlineText: break; case LegoUIType.PlaneToggle: BindingPlaneToggle(ui, id, uiRxModel, rectMeta); break; case LegoUIType.Component: break; case LegoUIType.Container: break; case LegoUIType.View: break; default: throw new ArgumentOutOfRangeException(nameof(elementType), elementType, null); } }
private void TryUnBingdngAtElementType(LegoUIType elementType, ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel) { }