public static LegoButtonMeta Create(YuLegoButton button)
        {
            var meta = new LegoButtonMeta
            {
                Interactable   = button.interactable,
                TransitionType = button.transition.ToString().AsEnum <LegoTransition>(),
                ButtonSoundId  = button.SoundEffectId,
                IsNonRectangularButtonImage = button.IsNonRectangularButtonImage
            };

            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);

            return(meta);
        }
示例#2
0
        public override void Metamorphose(LegoUIMeta uiMeta)
        {
            if (MetamorphoseStage == LegoMetamorphoseStage.Completed)
            {
                MetamorphoseStage = LegoMetamorphoseStage.Metamorphosing;
            }

            if (ButtonMeta == null)
            {
                ButtonMeta = uiMeta.NextButton;
                RectMeta   = uiMeta.CurrentRect;
            }

            switch (metamorphoseStatus)
            {
            // 按钮自身变形
            case MetamorphoseStatus.Button:
                MetamorphoseRect(RectMeta);
                if (ButtonMeta.TransitionType == LegoTransition.ColorTint &&
                    ButtonMeta.ColorTintMeta != null)
                {
                    var colorTintMeta = ButtonMeta.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
                    };
                }

                SoundEffectId = ButtonMeta.ButtonSoundId;

                metamorphoseStatus = MetamorphoseStatus.ButtonImage;
                break;

            case MetamorphoseStatus.ButtonImage:
                // 按钮附带的Image变形
                BgImage.As <YuLegoImage>().Metamorphose(ButtonMeta.ButtonImageMeta);
                if (ButtonMeta.IsNonRectangularButtonImage)
                {
                    IsNonRectangularButtonImage = true;
                    BgImage.As <YuLegoImage>().alphaHitTestMinimumThreshold =
                        ButtonMeta.ImageAlphaHitTestMinimumThreshold;
                }
                metamorphoseStatus = MetamorphoseStatus.SonText;
                break;

            case MetamorphoseStatus.SonText:
                if (ButtonMeta.IsTextActive)
                {
                    SonText.gameObject.SetActive(true);
                    SonText.Metamorphose(ButtonMeta.TextRect, ButtonMeta.TextMeta);
                }
                else
                {
                    SonText.gameObject.SetActive(false);
                }

                metamorphoseStatus = MetamorphoseStatus.Button;
                MetamorphoseStage  = LegoMetamorphoseStage.Completed;
                break;
            }
        }
示例#3
0
        private void AddButtonMeta(Transform transform)
        {
            var buttonMeta = LegoButtonMeta.Create(transform.GetComponent <YuLegoButton>());

            ButtonMetas.Add(buttonMeta);
        }