Пример #1
0
        private void AddDropdownMeta(Transform transform)
        {
            var dropdownMeta = LegoDropdownMeta.Create(
                transform.GetComponent <YuLegoDropdown>());

            DropdownMetas.Add(dropdownMeta);
        }
Пример #2
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();
            }
        }
Пример #3
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);
        }