示例#1
0
        private void OnViewBuilded(string lowerId, string bigId, LegoBuildTask buildTask)
        {
            var uiRect = buildTask.RootRect;
            //            loadingTaskIds.Remove(lowerId);
            ILegoView view = CodeLoader.GetView(uiRect);

            views.Add(lowerId, view);
            var uiMeta = MetaHelper.GetMeta(uiRect);

            //绑定子组件
            tempUis.Clear();
            foreach (var sonRef in uiMeta.ComponentRefs)
            {
                if (!uiLogicMap.ContainsKey(sonRef.LogicId))
                {
                    throw new Exception($"视图{bigId}的子组件{sonRef.LogicId}无法找到!");
                }

                var component = uiLogicMap[sonRef.LogicId];
                component.SetParentUi(view);
                tempUis.Add(component);
            }

            //数据模型与 UI 类型实例绑定
            var rxModel = (IYuLegoUIRxModel)ModelLoader.LoadModel(bigId);

            SetViewRxModel(rxModel, view);

            //UI 实体Rect,周期管理类型,子组件与 UI 脚本类型实例绑定
            var pipelineHandlers = PipelineLoader.GetHandlers(bigId);

            if (buildTask.IsInBackground)
            {
                view.Construct(uiRect, pipelineHandlers, tempUis, true);
            }
            else
            {
                view.Construct(uiRect, pipelineHandlers, tempUis);
            }

            //控制器
            TryInvokeViewUILogicer(view);

            // 修正界面的Z轴深度
            AddViewToDepthViews(view, uiMeta.ViewType);

            //数据模型数据与 UI 脚本类型实例绑定
            LegoBinder.Binding(view, uiMeta, rxModel);

            //构建完成回调
            buildTask.UiBuildCallback?.Invoke(view);

            //触发界面创建完成事件
            U3DEventModule.TriggerEvent(ProjectCoreEventCode.View_Created, view, null);
            view.ShowDefault();
        }
示例#2
0
        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);
        }