public void Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var text    = control as YuLegoText;
            var rxModel = model as YuLegoTextRxModel;

            rxModel.LocControl = text;

            rxModel.Content.BindingControl(text, text.ReceiveTextChange);
            rxModel.ColorStr.BindingControl(text, text.ReceiveColorChange);

            text.gameObject.SetActive(rectMeta.IsDefaultActive);
        }
        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 Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var rocker  = control as YuLegoRocker;
            var rxModel = model as YuLegoRockerRxModel;

            rxModel.LocControl = rocker;

            // 数据响应绑定
            rxModel.BgSpriteId.BindingControl(rocker.BgImage, rocker.OnBackGroundChange);
            rxModel.RockerSpriteId.BindingControl(rocker.RockerImage, rocker.OnRockerChange);

            rocker.gameObject.SetActive(rectMeta.IsDefaultActive);
        }
Example #4
0
        public void AddOperateMeta(LegoUIType elementType,
                                   LegoRectTransformMeta rectMeta, Transform transform)
        {
            ElementTypes.Add(elementType);
            RectMetas.Add(rectMeta);
            if (!AddMetaActions.ContainsKey(elementType))
            {
                Debug.LogError($"目标UI类型{elementType}当前没有对应的元数据构建委托!");
            }

            var action = AddMetaActions[elementType];

            action(transform);
        }
        private void BindingDropdown(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel
                                     , LegoRectTransformMeta rectMeta)
        {
            var binder = binderDict[typeof(YuLegoDropdown)];

            var oldModel = ui.RxModel.GetControlRxModel <YuLegoDropdownRxModel>(id);

            binder.UnBinding(oldModel);

            var dropdown = ui.GetControl <YuLegoDropdown>(id);
            var model    = uiRxModel.GetControlRxModel <YuLegoDropdownRxModel>(id);

            binder.Binding(dropdown, model, rectMeta);
        }
        private void BindingSlider(ILegoUI ui, string id, IYuLegoUIRxModel uiRxModel
                                   , LegoRectTransformMeta rectMeta)
        {
            var binder = binderDict[typeof(YuLegoSlider)];

            var oldModel = ui.RxModel.GetControlRxModel <YuLegoSliderRxModel>(id);

            binder.UnBinding(oldModel);

            var slider = ui.GetControl <YuLegoSlider>(id);
            var model  = uiRxModel.GetControlRxModel <YuLegoSliderRxModel>(id);

            binder.Binding(slider, model, rectMeta);
        }
Example #7
0
        public void Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var button  = control as YuLegoButton;
            var rxModel = model as YuLegoButtonRxModel;

            rxModel.LocControl = button;

            // 设置可交互状态
            button.Interactable = rxModel.LastInteractableValue;

            rxModel.BgSpriteId.BindingControl(button, button.ReceiveBgChange);
            rxModel.TextContent.BindingControl(button.SonText, button.ReceiveTextChange);

            button.GameObject.SetActive(rectMeta.IsDefaultActive);
        }
        public void Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var progressbar = control as YuLegoProgressbar;
            var rxModel     = model as YuLegoProgressbarRxModel;

            rxModel.LocControl = progressbar;

            // 设置可交互状态
            progressbar.Interactable = rxModel.LastInteractableValue;

            progressbar.Progress = rxModel.Progress.Value;
            rxModel.Progress.BindingControl(progressbar, progressbar.ReceiveProgressChange);

            progressbar.gameObject.SetActive(rectMeta.IsDefaultActive);
        }
Example #9
0
        private void PushSonTask(string taskId, LegoRectTransformMeta mountMeta, bool isSonComponent)
        {
            buildAble = false; // 暂停任务构建
            var task = TaskPool.GetTask(taskId, m_OnBuilded, RootRect);

            task.SetPushTaskDel(m_PushSonTaskDel)
            .SetBuildSpeed(m_BuildSpeed)
            .SetParentRect(RootRect)
            .SetMountMeta(mountMeta)
            .SetParentTask(this)
            .SetBackLoad(IsInBackground)
            .SetBindRxModel(isSonComponent && IsBindRxModelOnBuild);

            m_PushSonTaskDel(task);
        }
Example #10
0
        public static LegoRectTransformMeta Create(RectTransform rect)
        {
            var meta = new LegoRectTransformMeta
            {
                Name            = rect.name,
                IsDefaultActive = rect.gameObject.activeSelf,
                X = rect.localPosition.x,
                Y = rect.localPosition.y,
                Z = rect.localPosition.z
            };

            if (meta.X.Equal(0f) && meta.Y.Equal(0f) && meta.Z.Equal(0f))
            {
                meta.IsZeroPosition = true;
            }

            meta.Width  = rect.sizeDelta.x;
            meta.Height = rect.sizeDelta.y;

            meta.PivotMeta.PivotX = rect.pivot.x;
            meta.PivotMeta.PivotY = rect.pivot.y;

            meta.RotationX = rect.localRotation.eulerAngles.x;
            meta.RotationY = rect.localRotation.eulerAngles.y;
            meta.RotationZ = rect.localRotation.eulerAngles.z;
            if (meta.RotationX.Equal(0f) && meta.RotationY.Equal(0f) && meta.RotationZ.Equal(0f))
            {
                meta.IsZeroRotation = true;
            }

            // unity的缩放值由于是浮点数反序列化后会出现偏差。
            // 因此这里把所有轴的缩放值都和一个常量比较,达不到常量精度的都修正为1f。
            var localScale = rect.localScale;

            meta.ScaleX = localScale.x > scaleValue ? localScale.x : 1f;
            meta.ScaleY = localScale.y > scaleValue ? localScale.y : 1f;
            meta.ScaleZ = localScale.z > scaleValue ? localScale.z : 1f;
            if (meta.ScaleX.Equal(1f) && meta.ScaleY.Equal(1f) && meta.ScaleZ.Equal(1f))
            {
                meta.IsScaleOne = true;
            }

            // 扫描UI特效以构建特效元数据
            meta.CreateUIEffectMeta(rect);

            return(meta);
        }
Example #11
0
        public static void MetamorphoseRect(RectTransform rect, LegoRectTransformMeta rectMeta)
        {
            rect.name = rectMeta.Name;

            // 设置Pivot
            //rect.pivot = new Vector2(rectMeta.PivotMeta.PivotX,
            //    rectMeta.PivotMeta.PivotY);

            if (!rectMeta.IsZeroPosition)
            {
                rect.localPosition = new Vector3(
                    rectMeta.X,
                    rectMeta.Y,
                    rectMeta.Z
                    );
            }

            if (!rectMeta.IsZeroRotation)
            {
                rect.localRotation = Quaternion.Euler(
                    rectMeta.RotationX,
                    rectMeta.RotationY,
                    rectMeta.RotationZ
                    );
            }

            if (!rectMeta.IsScaleOne)
            {
                rect.localScale = new Vector3(
                    rectMeta.ScaleX,
                    rectMeta.ScaleY,
                    rectMeta.ScaleZ
                    );
            }
            else
            {
                rect.localScale = Vector3.one;
            }

            rect.sizeDelta = new Vector2(rectMeta.Width, rectMeta.Height);

            if (!rectMeta.IsDefaultActive)
            {
                rect.gameObject.SetActive(false);
            }
        }
Example #12
0
        public void Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var inputField = control as YuLegoInputField;
            var rxModel    = model as YuLegoInputFieldRxModel;

            rxModel.LocControl = inputField;

            // 设置可交互状态
            inputField.Interactable = rxModel.LastInteractableValue;

            // 双向绑定
            rxModel.Content.BindingControl(inputField, inputField.ReceiveContentChange);
            inputField.BindingPush(rxModel.Content.ReceiveControlChange);
            // 背景绑定
            rxModel.BackgroundSpriteId.BindingControl(inputField, inputField.ReceiveBackgroundChange);

            inputField.GameObject.SetActive(rectMeta.IsDefaultActive);
        }
Example #13
0
        public static LegoTButtonMeta Create(YuLegoTButton button)
        {
            var meta = new LegoTButtonMeta
            {
                Interactable   = button.interactable,
                TransitionType = button.transition.ToString().AsEnum <LegoTransition>()
            };

            switch (meta.TransitionType)
            {
            case LegoTransition.None:
                break;

            case LegoTransition.ColorTint:
                meta.ColorTintMeta = LegoColorTintMeta.Create(button);
                break;

            case LegoTransition.SpriteSwap:
                meta.SpriteSwapMeta = LegoSpriteSwapMeta.create(button);
                break;

            case LegoTransition.Animation:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // 按钮上的图片
            meta.ButtonImageMeta = LegoImageMeta.Create(button.BgImage.As <YuLegoImage>());

            // 子文本
            meta.IsTextActive = button.SonText.gameObject.activeSelf;
            meta.TextRect     = LegoRectTransformMeta.Create(button.SonText.rectTransform);
            meta.TextMeta     = LegoTextMeta.Create(button.SonText);

            // 图标图片
            meta.IconRectMeta  = LegoRectTransformMeta.Create(button.IconImage.RectTransform);
            meta.IconImageMeta = LegoImageMeta.Create(button.IconImage.As <YuLegoImage>());

            return(meta);
        }
        public void Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var tButton = control as YuLegoTButton;
            var rxModel = model as YuLegoTButtonRxModel;

            rxModel.LocControl = tButton;

            // 初始化赋值给控件
            tButton.SonText.Text = rxModel.TextContent.Value;

            // 设置可交互状态
            tButton.Interactable = rxModel.LastInteractableValue;

            rxModel.BgSpriteId.BindingControl(tButton, tButton.ReceiveBgChange);
            rxModel.IconSpriteId.BindingControl(tButton, tButton.ReceiveIconChange);
            rxModel.TextContent.BindingControl(tButton, tButton.ReceiveTextChange);

            // 设置按钮的默认激活
            tButton.GameObject.SetActive(rectMeta.IsDefaultActive);
        }
Example #15
0
        public static LegoComponentRef Create(RectTransform rect)
        {
            string path = null;
            var    view = rect.FindParent <YuLegoViewHelper>(out path);

            if (view == null)
            {
                throw new Exception("乐高组件必须置于乐高视图下");
            }

            var meta = new LegoComponentRef
            {
                RefComponent  = GetComponentId(rect),
                MountPath     = path,
                LogicId       = rect.name,
                MountPosition = LegoRectTransformMeta.Create(rect),
            };

            return(meta);
        }
Example #16
0
        public static LegoContainerRef Create(RectTransform rect)
        {
            string path = null;
            var    view = rect.FindParent <YuLegoViewHelper>(out path);

            if (view == null)
            {
                var component = rect.FindParent <YuLegoComponentHelper>(out path);
                throw new Exception("乐高容器必须置于乐高视图或者乐高组件下");
            }

            var meta = new LegoContainerRef
            {
                ContainerName = rect.name,
                MountPath     = path,
                MountPosition = LegoRectTransformMeta.Create(rect)
            };

            return(meta);
        }
Example #17
0
        public void Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var toggle  = control as YuLegoPlaneToggle;
            var rxModel = model as YuLegoPlaneToggleRxModel;

            rxModel.LocControl = toggle;

            toggle.IsOn = rxModel.IsOn.Value; // 初始化赋值

            // 设置可交互状态
            toggle.Interactable = rxModel.LastInteractableValue;

            rxModel.IsOn.BindingControl(toggle, toggle.ReceiveIsOnChange);
            toggle.BindingPush(rxModel.IsOn.ReceiveControlChange);

            // 背景、checkmark、文本
            rxModel.FrontSpriteId.BindingControl(toggle, toggle.ReveiveFrontSpriteChange);
            rxModel.BackgroundSpriteId.BindingControl(toggle, toggle.ReveiveBackgroundSpriteChange);

            toggle.GameObject.SetActive(rectMeta.IsDefaultActive);
        }
Example #18
0
        public void Binding(object control, object model, LegoRectTransformMeta rectMeta)
        {
            var slider  = control as YuLegoSlider;
            var rxModel = model as YuLegoSliderRxModel;

            rxModel.LocControl = slider;


            // 设置可交互状态
            slider.Interactable = rxModel.LastInteractableValue;

            rxModel.Direction.BindingControl(slider, slider.ReceiveDirectionChange);
            rxModel.Progress.BindingControl(slider, slider.ReceiveValueChange);
            rxModel.MinValue.BindingControl(slider, slider.ReceiveMinValueChange);
            rxModel.MaxValue.BindingControl(slider, slider.ReceiveMaxValueChange);
            rxModel.IsWholeNumbers.BindingControl(slider, slider.ReceiveIsWholeNumbersChange);

            slider.BindingPush(rxModel.Progress.ReceiveControlChange);

            slider.gameObject.SetActive(rectMeta.IsDefaultActive);
        }
Example #19
0
        public void Metamorphose(LegoRectTransformMeta rectMeta, LegoTextMeta textMeta)
        {
            originalSizeDelta = RectTransform.sizeDelta;
            YuLegoUtility.MetamorphoseRect(RectTransform, rectMeta);
            Text          = textMeta.Content;
            raycastTarget = textMeta.RaycastTarget;

            font = GetFont(textMeta.FontId.ToLower());
            //color = textMeta.Color.ToColor();
            fontStyle            = (FontStyle)(int)textMeta.FontStyle;
            fontSize             = textMeta.FontSize;
            lineSpacing          = textMeta.LineSpacing;
            supportRichText      = textMeta.RichText;
            resizeTextForBestFit = textMeta.BestFit;
            alignByGeometry      = textMeta.AlignByGeometry;

            alignment          = (TextAnchor)(int)textMeta.Alignment;
            verticalOverflow   = (VerticalWrapMode)(int)textMeta.VerticalOverflow;
            horizontalOverflow = (HorizontalWrapMode)(int)textMeta.HorizontalOverflow;
            UpdateAtStyleId();
        }
        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 static LegoScrollViewMeta Create(YuLegoScrollView legoScrollView)
        {
            var scHelper = legoScrollView.GetComponent <YuLegoScrollViewHelper>();

            if (scHelper == null)
            {
                throw new Exception($"滚动视图{legoScrollView.Name}上没有发现滚动视图开发助手组件!");
            }

            var meta = new LegoScrollViewMeta
            {
                Id                    = legoScrollView.Name,
                Arrangement           = legoScrollView.Arrangement,
                ItemWidth             = scHelper.IitemWidth,
                ItemHeight            = scHelper.ItemHeight,
                IsHorizontal          = scHelper.IsHorizontal,
                HorizontalEnable      = scHelper.HorizontalEnable,
                VerticalEnable        = scHelper.VerticalEnable,
                IsMultiLayout         = scHelper.IsMulti,
                MaxPerLine            = scHelper.MaxPerLine,
                Xoffset               = scHelper.Xoffset,
                IsNotInitSonComponent = scHelper.IsNotInitSonComponent,
                HorizontalPadiding    = scHelper.Horizontalpadiding,
                VerticalPadiding      = scHelper.VerticalPadiding,
                ScrollViewImageMeta   = LegoImageMeta
                                        .Create(legoScrollView.RectTransform.GetComponent <YuLegoImage>())
            };

            var scrollRect = legoScrollView.RectTransform.Find("ScrollRect").RectTransform();

            meta.ScrollRectRectMeta  = LegoRectTransformMeta.Create(scrollRect);
            meta.ScrollRectImageMeta = LegoImageMeta.Create(scrollRect.GetComponent <YuLegoImage>());

            var content = scrollRect.Find("Content").RectTransform();

            meta.ContentRectMeta = LegoRectTransformMeta.Create(content);

            return(meta);
        }
        public static LegoSliderMeta Create(YuLegoSlider slider)
        {
            var meta = new LegoSliderMeta();
            var rect = slider.RectTransform;

            meta.Transition = slider.transition.ToString()
                              .AsEnum <LegoTransition>();
            meta.ColorTintMeta = LegoColorTintMeta.Create(slider);

            var background = rect.Find("Background");

            meta.BackgroundImageRect = LegoRectTransformMeta.Create(background.RectTransform());
            meta.BackgroundImageMeta = LegoImageMeta.Create(background.GetComponent <YuLegoImage>());

            var fillArea = rect.Find("Fill Area");

            meta.FillAreaMeta = LegoRectTransformMeta.Create(fillArea.RectTransform());

            var fill = rect.Find("Fill Area/Fill");

            meta.FillImageRect = LegoRectTransformMeta.Create(fill.RectTransform());
            meta.FillImageMeta = LegoImageMeta.Create(fill.GetComponent <YuLegoImage>());

            var handleSlideArea = rect.Find("Handle Slide Area");

            meta.HandleSlideAreaRect = LegoRectTransformMeta.Create(handleSlideArea.RectTransform());

            var handle = rect.Find("Handle Slide Area/Handle");

            meta.HandleImageRect = LegoRectTransformMeta.Create(handle.RectTransform());
            meta.HandleImageMeta = LegoImageMeta.Create(handle.GetComponent <YuLegoImage>());

            meta.Direction      = slider.direction;
            meta.MinValue       = slider.minValue;
            meta.MaxValue       = slider.maxValue;
            meta.IsWholeNumbers = slider.wholeNumbers;

            return(meta);
        }
        public static LegoPlaneToggleMeta Create(YuLegoPlaneToggle toggle)
        {
            var rect = toggle.RectTransform;
            var meta = new LegoPlaneToggleMeta
            {
                Interactable   = toggle.interactable,
                TransitionType = toggle.transition.ToString().AsEnum <LegoTransition>(),
                ColorTintMeta  = LegoColorTintMeta.Create(toggle),
                SoundId        = toggle.SoundEffectId
            };

            // 开关自身图片元数据
            meta.ToggleImageMeta = LegoImageMeta.Create(toggle.ToggleImage.As <YuLegoImage>());

            var imageFrontPoint = rect.Find(IMAGE_FRONT_POINT);

            meta.ImageFrontPointRectMeta = LegoRectTransformMeta
                                           .Create(imageFrontPoint.RectTransform());
            meta.ImageFrontPointImageMeta = LegoImageMeta
                                            .Create(imageFrontPoint.GetComponent <YuLegoImage>());

            return(meta);
        }
Example #24
0
        public void Init()
        {
            RootMeta         = new LegoRectTransformMeta();
            ElementTypes     = new List <LegoUIType>();
            ComponentRefs    = new List <LegoComponentRef>();
            ContainerRefs    = new List <LegoContainerRef>();
            RectMetas        = new List <LegoRectTransformMeta>();
            TextMetas        = new List <LegoTextMeta>();
            ButtonMetas      = new List <LegoButtonMeta>();
            TButtonMetas     = new List <LegoTButtonMeta>();
            ImageMetas       = new List <LegoImageMeta>();
            RawImageMetas    = new List <LegoRawImageMeta>();
            SliderMetas      = new List <LegoSliderMeta>();
            ProgressbarMetas = new List <LegoProgressbarMeta>();
            ToggleMetas      = new List <LegoToggleMeta>();
            PlaneToggleMetas = new List <LegoPlaneToggleMeta>();
            InputFieldMetas  = new List <LegoInputFieldMeta>();
            DropdownMetas    = new List <LegoDropdownMeta>();
            ScrollViewMetas  = new List <LegoScrollViewMeta>();
            RockerMetas      = new List <LegoRockerMeta>();

            AddMetaActions = new Dictionary <LegoUIType, Action <Transform> >();
            InitAddMetActions();
        }
Example #25
0
 protected void MetamorphoseRect(LegoRectTransformMeta rectMeta)
 {
     YuLegoUtility.MetamorphoseRect(RectTransform, rectMeta);
 }
Example #26
0
        //private Sprite GetSprite(YuLegoDropdownOptionMeta optionMeta)
        //{
        //    var spriteId = optionMeta.SpriteId;

        //    if (spriteDict.ContainsKey(spriteId))
        //    {
        //        return spriteDict[spriteId].GetAsset();
        //    }

        //    var spRef = AssetModule.GetSprite(spriteId);
        //    spriteDict.Add(spriteId, spRef);
        //    return spRef.GetAsset();
        //}

        #endregion

        public override void Metamorphose(LegoUIMeta uiMeta)
        {
            if (MetamorphoseStage == LegoMetamorphoseStage.Completed)
            {
                MetamorphoseStage = LegoMetamorphoseStage.Metamorphosing;
            }

            if (dropdownMeta == null)
            {
                dropdownMeta     = uiMeta.NextDropdown;
                dropdownRectMeta = uiMeta.CurrentRect;
            }

            switch (metamorphoseStatus)
            {
            case MetamorphoseStatus.Dropdown:
                MetamorphoseRect(dropdownRectMeta);

                // 输入框自身附带Image控件变形
                SelfImage.Metamorphose(dropdownMeta.DropdownImageMeta);

                if (dropdownMeta.Transition == LegoTransition.ColorTint)
                {
                    var colorTintMeta = dropdownMeta.ColorTintMeta;

                    colors = new ColorBlock
                    {
                        normalColor      = colorTintMeta.NormalLegoColor.ToColor(),
                        highlightedColor = colorTintMeta.HighlightedLegoColor.ToColor(),
                        pressedColor     = colorTintMeta.PressedLegoColor.ToColor(),
                        disabledColor    = colorTintMeta.DisabledLegoColor.ToColor(),
                        colorMultiplier  = colorTintMeta.ColorMultiplier,
                        fadeDuration     = colorTintMeta.FadeDuration
                    };
                }

                // 选项
                if (dropdownMeta.OptionMetas != null && dropdownMeta.OptionMetas.Count > 0)
                {
                    options.Clear();

                    foreach (var optionMeta in dropdownMeta.OptionMetas)
                    {
                        var optionData = new OptionData();
                        optionData.text = optionMeta.Text;
                        // todo 下拉框菜单精灵

                        //optionData.image = SpriteRouter.GetSprite(optionMeta.SpriteId);
                        options.Add(optionData);
                    }
                }

                metamorphoseStatus = MetamorphoseStatus.Label;
                break;

            case MetamorphoseStatus.Label:
                Label.Metamorphose(dropdownMeta.LabelRectMeta, dropdownMeta.LabelTextMeta);
                metamorphoseStatus = MetamorphoseStatus.Arrow;
                break;

            case MetamorphoseStatus.Arrow:
                Arrow.Metamorphose(dropdownMeta.ArrowRectMeta, dropdownMeta.ArrowImageMeta);
                metamorphoseStatus = MetamorphoseStatus.Template;
                break;

            case MetamorphoseStatus.Template:
                TemplateImage.Metamorphose(dropdownMeta.TemplateRectMeta, dropdownMeta.TemplateImageMeta);
                metamorphoseStatus = MetamorphoseStatus.Viewport;
                break;

            case MetamorphoseStatus.Viewport:
                ViewportImage.Metamorphose(dropdownMeta.ViewPortRectMeta, dropdownMeta.ViewPortImageMeta);
                metamorphoseStatus = MetamorphoseStatus.Content;
                break;

            case MetamorphoseStatus.Content:
                YuLegoUtility.MetamorphoseRect(Content, dropdownMeta.ContentRectMeta);
                metamorphoseStatus = MetamorphoseStatus.Item;
                break;

            case MetamorphoseStatus.Item:
                if (dropdownMeta.ItemTransition == LegoTransition.ColorTint)
                {
                    var colorTintMeta = dropdownMeta.ItemRootColorTintMeta;

                    Item.colors = new ColorBlock
                    {
                        normalColor      = colorTintMeta.NormalLegoColor.ToColor(),
                        highlightedColor = colorTintMeta.HighlightedLegoColor.ToColor(),
                        pressedColor     = colorTintMeta.PressedLegoColor.ToColor(),
                        disabledColor    = colorTintMeta.DisabledLegoColor.ToColor(),
                        colorMultiplier  = colorTintMeta.ColorMultiplier,
                        fadeDuration     = colorTintMeta.FadeDuration
                    };
                }

                YuLegoUtility.MetamorphoseRect(Item.RectTransform, dropdownMeta.ItemRootRectMeta);
                metamorphoseStatus = MetamorphoseStatus.ItemBackground;
                break;

            case MetamorphoseStatus.ItemBackground:
                ItemBackground.Metamorphose(dropdownMeta.ItemBackgroundRectMeta,
                                            dropdownMeta.ItemBackgroundImageMeta);
                metamorphoseStatus = MetamorphoseStatus.ItemCheckmark;
                break;

            case MetamorphoseStatus.ItemCheckmark:
                ItemCheckmark.Metamorphose(dropdownMeta.ItemCheckmarkRectMeta,
                                           dropdownMeta.ItemCheckmarkImageMeta);
                metamorphoseStatus = MetamorphoseStatus.ItemLabel;
                break;

            case MetamorphoseStatus.ItemLabel:
                ItemLabel.Metamorphose(dropdownMeta.ItemLabelRectMeta,
                                       dropdownMeta.ItemLabelTextMeta);
                metamorphoseStatus = MetamorphoseStatus.Scrollbar;
                break;

            case MetamorphoseStatus.Scrollbar:
                ScrollbarImage.Metamorphose(dropdownMeta.ScrollbarRectMeta,
                                            dropdownMeta.ScrollbarImageMeta);
                metamorphoseStatus = MetamorphoseStatus.SlidingArea;
                break;

            case MetamorphoseStatus.SlidingArea:
                YuLegoUtility.MetamorphoseRect(SlidingArea, dropdownMeta.SlidingAreaRectMeta);
                metamorphoseStatus = MetamorphoseStatus.Handle;
                break;

            case MetamorphoseStatus.Handle:
                HandleImage.Metamorphose(dropdownMeta.ScrollbarHandleRectMeta,
                                         dropdownMeta.ScrollbarHandleImageMeta);

                dropdownMeta       = null;
                dropdownRectMeta   = null;
                metamorphoseStatus = MetamorphoseStatus.Dropdown;
                MetamorphoseStage  = LegoMetamorphoseStage.Completed;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        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);
        }
Example #28
0
 /// <summary>
 /// 设置UI的挂载位置元数据(仅仅组件需要设置该属性,界面会直接挂载在0,0的位置)。
 /// </summary>
 /// <param name="mountMeta"></param>
 /// <returns></returns>
 public LegoBuildTask SetMountMeta(LegoRectTransformMeta mountMeta)
 {
     ComponentMountMeta = mountMeta;
     return(this);
 }
        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);
            }
        }
Example #30
0
        public static LegoDropdownMeta Create(YuLegoDropdown dropdown)
        {
            var meta = new LegoDropdownMeta
            {
                Transition    = dropdown.transition.ToString().AsEnum <LegoTransition>(),
                ColorTintMeta = LegoColorTintMeta.Create(dropdown),
                OptionMetas   = new List <YuLegoDropdownOptionMeta>(),
            };

            var dropdownImage = dropdown.RectTransform.GetComponent <YuLegoImage>();

            meta.DropdownImageMeta = LegoImageMeta.Create(dropdownImage);

            foreach (var optionData in dropdown.options)
            {
                var optionMeta = YuLegoDropdownOptionMeta.Create(optionData);
                meta.OptionMetas.Add(optionMeta);
            }

            var label = dropdown.RectTransform.Find("Label")
                        .GetComponent <YuLegoText>();

            meta.LabelRectMeta = LegoRectTransformMeta.Create(label.rectTransform);
            meta.LabelTextMeta = LegoTextMeta.Create(label);

            var arrow = dropdown.RectTransform.Find("Arrow")
                        .GetComponent <YuLegoImage>();

            meta.ArrowRectMeta  = LegoRectTransformMeta.Create(arrow.RectTransform);
            meta.ArrowImageMeta = LegoImageMeta.Create(arrow);

            var template = dropdown.RectTransform.Find("Template")
                           .GetComponent <RectTransform>();

            meta.TemplateRectMeta  = LegoRectTransformMeta.Create(template);
            meta.TemplateImageMeta = LegoImageMeta.Create(template.GetComponent <YuLegoImage>());

            var viewport = template.Find("Viewport").GetComponent <RectTransform>();

            meta.ViewPortRectMeta  = LegoRectTransformMeta.Create(viewport);
            meta.ViewPortImageMeta = LegoImageMeta.Create(viewport.GetComponent <YuLegoImage>());

            var content = viewport.Find("Content").GetComponent <RectTransform>();

            meta.ContentRectMeta = LegoRectTransformMeta.Create(content);

            var item = content.Find("Item").GetComponent <RectTransform>();

            meta.ItemRootRectMeta = LegoRectTransformMeta.Create(item);
            var itemRootToggle = item.GetComponent <YuLegoToggle>();

            meta.ItemTransition          = itemRootToggle.transition.ToString().AsEnum <LegoTransition>();
            meta.ItemRootColorTintMeta   = LegoColorTintMeta.Create(itemRootToggle);
            meta.ItemRootTargetGraphicId = itemRootToggle.targetGraphic.name;

            var itemBackground = item.Find("Item Background").GetComponent <RectTransform>();

            meta.ItemBackgroundRectMeta  = LegoRectTransformMeta.Create(itemBackground);
            meta.ItemBackgroundImageMeta = LegoImageMeta.Create(itemBackground.GetComponent <YuLegoImage>());

            var itemCheckmark = item.Find("Item Checkmark").GetComponent <RectTransform>();

            meta.ItemCheckmarkRectMeta  = LegoRectTransformMeta.Create(itemCheckmark);
            meta.ItemCheckmarkImageMeta = LegoImageMeta.Create(itemCheckmark.GetComponent <YuLegoImage>());

            var itemLabel = item.Find("Item Label").GetComponent <RectTransform>();

            meta.ItemLabelRectMeta = LegoRectTransformMeta.Create(itemLabel);
            meta.ItemLabelTextMeta = LegoTextMeta.Create(itemLabel.GetComponent <YuLegoText>());

            var scrollbar = template.Find("Scrollbar").GetComponent <RectTransform>();

            meta.ScrollbarRectMeta  = LegoRectTransformMeta.Create(scrollbar);
            meta.ScrollbarImageMeta = LegoImageMeta.Create(scrollbar.GetComponent <YuLegoImage>());

            var slidingArea = scrollbar.Find("Sliding Area").GetComponent <RectTransform>();

            meta.SlidingAreaRectMeta = LegoRectTransformMeta.Create(slidingArea);

            var slidingAreaHandle = slidingArea.Find("Handle").GetComponent <RectTransform>();

            meta.ScrollbarHandleRectMeta  = LegoRectTransformMeta.Create(slidingAreaHandle);
            meta.ScrollbarHandleImageMeta = LegoImageMeta.Create(slidingAreaHandle.GetComponent <YuLegoImage>());

            return(meta);
        }