Ejemplo n.º 1
0
        private void OnBuilded(LegoBuildTask buildTask)
        {
            var bigId   = buildTask.RootRect.name;
            var lowerId = bigId;//// YuBigAssetIdMap.GetLowerId(bigId);

            if (lowerId.StartsWith(LEGO_VIEW))
            {
                OnViewBuilded(lowerId, bigId, buildTask);
            }
            else if (lowerId.StartsWith(LEGO_COMPONENT))
            {
                if (buildTask.ComponentMountMeta != null)
                {
                    OnSonComponentLoaded(lowerId, buildTask);
                }
                else
                {
                    OnSingleComponentLoaded(lowerId, buildTask);
                }
            }
            else
            {
                SetComponentPosition(buildTask, null);
            }

            TryStartNextTask();
        }
Ejemplo n.º 2
0
        private void SetComponentPosition(LegoBuildTask buildTask, RectTransform customParentRect)
        {
            var uiRect     = buildTask.RootRect;
            var parentRect = customParentRect == null ? buildTask.ParentRect : customParentRect;
            var rectMeta   = buildTask.ComponentMountMeta;

            uiRect.name = rectMeta.Name;
            uiRect.SetParent(parentRect);
            uiRect.gameObject.layer = parentRect.gameObject.layer;

            uiRect.localPosition = new Vector3(
                rectMeta.X,
                rectMeta.Y,
                rectMeta.Z
                );

            uiRect.localScale = new Vector3(
                rectMeta.ScaleX,
                rectMeta.ScaleY,
                rectMeta.ScaleZ
                );

            if (!buildTask.IsInBackground)
            {
                uiRect.gameObject.SetActive(rectMeta.IsDefaultActive);
            }
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 加载 View 或 Component 中子组件内部回调
        /// </summary>
        private void OnSonComponentLoaded(string lowerId, LegoBuildTask buildTask)
        {
            buildTask.RootRect.name = buildTask.ComponentMountMeta.Name;
            var bigId      = buildTask.RootRect.name;
            var uiRect     = buildTask.RootRect;
            var parentRect = buildTask.ParentRect;

            SetComponentPosition(buildTask, parentRect);
            var component = CodeLoader.GetComponent(uiRect);

            if (uiLogicMap.ContainsKey(uiRect.name))
            {
                uiLogicMap[uiRect.name] = component;
            }
            else
            {
                uiLogicMap.Add(uiRect.name, component);
            }

            var uiMeta = MetaHelper.GetMeta(lowerId);

            tempUis.Clear();

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

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

            var  pipelineHandlers = PipelineLoader.GetHandlers(bigId);
            bool isSonOfComponent = parentRect.name.Contains("LegoComponent");
            var  rxModel          = isSonOfComponent
                ? (IYuLegoUIRxModel)ModelLoader.CreateModel(bigId)
                : (IYuLegoUIRxModel)ModelLoader.LoadModel(bigId);

            SetViewSonComponentRxModel(rxModel, component);
            component.Construct(uiRect, pipelineHandlers, tempUis);
            LegoBinder.Binding(component, uiMeta, rxModel);
            TryInvokeComponentUILogicer(component);
            component.ShowDefault();
            if (component.SonComponentDict.Count != 0)
            {
                BindSonComponentRxmodel(rxModel, component);
            }
        }
Ejemplo n.º 5
0
 public void Reset()
 {
     buildAble            = false;
     IsComplete           = false;
     BuildedCount         = 0;
     m_BuildSpeed         = 0;
     buildingControl      = null;
     ComponentMountMeta   = null;
     containerBuildedNum  = 0;
     sonBuildedNum        = 0;
     m_ParentTask         = null;
     UiBuildCallback      = null;
     IsBindRxModelOnBuild = true;
     IsInBackground       = false;
     ParentRect           = null;
 }
 public void RestoreTask(LegoBuildTask task)
 {
     TaskPool.Restore(task);
 }
Ejemplo n.º 7
0
 public void PushSonTask(LegoBuildTask task)
 {
     taskStack.Push(task);
 }
Ejemplo n.º 8
0
        public void Update()
        {
            if (!buildAble)
            {
                return;
            }

            buildFrameCount++;
            int loopTimeOutCount = 0;

            while (true)
            {
                loopTimeOutCount++;
                if (loopTimeOutCount > BuildMaxloopTime)
                {
#if DEBUG
                    Debug.LogError($"该界面构建帧超时退出!");
#endif
                    return;
                }
                //构建任务栈为空
                if (taskStack.Count == 0)
                {
                    buildAble = false;
                    AllCompleted?.Invoke();
                    AllCompleted = null; // 每次都置空完全构建完毕回调
                    //Debug.Log($"该界面构造帧数为 : {buildFrameCount}");
                    //Debug.Log($"该界面构造耗时为 : {CostTime}毫秒!");

                    buildFrameCount = 0;
                    return;
                }
                //获取当前任务,判断是否已完成,未完成则继续构建
                currentTask = taskStack.Peek();
                if (currentTask.IsComplete)
                {
                    currentTask.Reset();
                    TaskPool.RestoreTask(currentTask);
                    taskStack.Pop();
                    continue;
                }

                try
                {
                    currentTask.BuildAtUpdate();
                    buildedCount += currentTask.BuildedFrameCount;
                    if (buildedCount >= this.buildWorkPerFrame)
                    {
                        buildedCount = 0;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    DestroySelf();
#if DEBUG
                    Debug.LogError($"UI{currentTask.TaskMeta.RootMeta.Name}构建失败!");
                    Debug.LogError(ex.Message + ex.StackTrace);
#endif
                    currentTask.Reset();
                    TaskPool.RestoreTask(currentTask);
                    taskStack.Pop();

#if UNITY_EDITOR
                    Application.Quit();
#endif
                }
            }
        }
Ejemplo n.º 9
0
 public LegoBuildTask SetParentTask(LegoBuildTask parentTask)
 {
     m_ParentTask = parentTask;
     return(this);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 单独加载组件内部回调
        /// </summary>
        private void OnSingleComponentLoaded(string lowerId, LegoBuildTask buildTask)
        {
            var bigId      = buildTask.RootRect.name;
            var uiRect     = buildTask.RootRect;
            var parentRect = mountPointDict[buildTask.ParentCanvas];
            var uiMeta     = MetaHelper.GetMeta(uiRect);
            var rectMeta   = uiMeta.RootMeta;

            uiRect.name = rectMeta.Name;
            uiRect.SetParent(parentRect);
            uiRect.localPosition = new Vector3(
                rectMeta.X,
                rectMeta.Y,
                rectMeta.Z
                );

            uiRect.localScale = new Vector3(
                rectMeta.ScaleX,
                rectMeta.ScaleY,
                rectMeta.ScaleZ
                );

            if (!buildTask.IsInBackground)
            {
                uiRect.gameObject.SetActive(rectMeta.IsDefaultActive);
            }

            var component = CodeLoader.GetComponent(uiRect);

            if (uiLogicMap.ContainsKey(uiRect.name))
            {
                uiLogicMap[uiRect.name] = component;
            }
            else
            {
                uiLogicMap.Add(uiRect.name, component);
            }

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

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

            var pipelineHandlers = PipelineLoader.GetHandlers(bigId);
            var rxModel          = (IYuLegoUIRxModel)ModelLoader.CreateModel(uiRect.name);

            SetViewSonComponentRxModel(rxModel, component);
            component.Construct(uiRect, pipelineHandlers, tempUis);
            // todo IsBindRxModelOnBuild设计原由说明补全
            TryInvokeComponentUILogicer(component);
            if (buildTask.IsBindRxModelOnBuild)
            {
                LegoBinder.Binding(component, uiMeta, rxModel);
                component.ShowDefault();
                if (component.SonComponentDict.Count != 0)
                {
                    BindSonComponentRxmodel(rxModel, component);
                }
            }

            try
            {
                buildTask.UiBuildCallback?.Invoke(component);
            }
            catch (Exception e)
            {
#if DEBUG
                Debug.LogError(e.Message + e.StackTrace);
#endif
            }
        }