// ------------------------------------- @AnimateCharacterSequence
        // ---------------------------------------------------------------
        /// <summary>
        /// Animate the height of target element to desired value
        /// </summary>
        /// <param name="target">VisualElement to animate</param>
        /// <param name="startColor">Initial height of element</param>
        /// <param name="endColor">Desired ending height after animation</param>
        /// <param name="cascadeMs">The length of time in which each subsequent animation in the sequence will be offset (in milliseconds)</param>
        /// <param name="durationMS">The amount of time in which the animation will complete from start to finish (in milliseconds)</param>
        /// <param name="reverse">Animation will play in reverse, from right to left</param>
        /// <param name="callback">Function that can be called when the animation is completed</param>
        public static List <ValueAnimation <StyleValues> > AnimCharacterSequence(this VisualElement target, Color startColor, Color endColor, int cascadeMs, int durationMS,
                                                                                 bool reverse    = false,
                                                                                 Action callback = null,
                                                                                 float flexBasis = default)
        {
            var animatedValues = new List <ValueAnimation <StyleValues> >();
            IEnumerable <string>    originalStyle = new List <string>();
            IEnumerable <string>    resolvedStyle = new List <string>();
            VisualElementStyleStore styleData     = new VisualElementStyleStore();
            var textString = "";

            Label labelRef = new Label();

            if (target is AnimatedLabel label)
            {
                labelRef             = label.GetLabel();
                textString           = label.text;
                styleData            = label.CreateStyleData();
                styleData.SourceName = target.name;
            }

            if (doDebug)
            {
                var table = new TableBuilder();
                table.WithHeader("Name", "Value", "GetProperties - AnimSeq - l-54");
                var fields = styleData.GetType().GetProperties().ToList();
                fields.ForEach(x => { table.WithRow(x.Name, x.GetValue(styleData)); });
                table.ToConsole();
            }

            new VisualElement().Create(out var animatedContainer).ToUSS(nameof(animatedContainer), "animated-label-container");
            animatedContainer.style.height = new StyleLength(StyleKeyword.Auto);

            List <Label> labelList = new List <Label>();

            for (int i = 0; i < textString.Length; i++)
            {
                Label animLabel = new Label();

                if (!doDebug)
                {
                    animLabel = styleData.FromStyleData(new Label(textString[i].ToString()));
                }
                else if (i == 0)
                {
                    animLabel = styleData.FromStyleData(new Label(textString[i].ToString()), doDebug);
                }

                if (!flexBasis.Equals(default))
Пример #2
0
        // -- Apply Style data to element from StyleStore ----------------
        public static T FromStyleData <T>(this VisualElementStyleStore source, T target, bool buildTable = false) where T : VisualElement
        {
            var styleValues = new Dictionary <string, object>
            {
                { nameof(target.style.width), target.style.width = source.Width },
                { nameof(target.style.height), target.style.height = source.Height },
                {
                    nameof(target.style.maxWidth), target.style.maxWidth =
                        (source.MaxWidth.value == 0 || source.MaxWidth == StyleKeyword.Null) ? new StyleLength(StyleKeyword.Auto) : source.MaxWidth.value
                },
                { nameof(target.style.maxHeight), target.style.maxHeight = source.MaxHeight.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.MaxHeight.value },
                { nameof(target.style.minWidth), target.style.minWidth = source.MinWidth.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.MinWidth.value },
                { nameof(target.style.minHeight), target.style.minHeight = source.MinHeight.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.MinHeight.value },
                { nameof(target.style.flexBasis), target.style.flexBasis = source.FlexBasis.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.FlexBasis.value },
                { nameof(target.style.flexGrow), target.style.flexGrow = source.FlexGrow },
                { nameof(target.style.flexShrink), target.style.flexShrink = source.FlexShrink },
                { nameof(target.style.flexDirection), target.style.flexDirection = (FlexDirection)source.FlexDirection.value },
                { nameof(target.style.flexWrap), target.style.flexWrap = (Wrap)source.FlexWrap.value },
                { nameof(target.style.marginLeft), target.style.marginLeft = source.MarginLeft },
                { nameof(target.style.marginTop), target.style.marginTop = source.MarginTop },
                { nameof(target.style.marginRight), target.style.marginRight = source.MarginRight },
                { nameof(target.style.marginBottom), target.style.marginBottom = source.MarginBottom },
                { nameof(target.style.paddingLeft), target.style.paddingLeft = source.PaddingLeft },
                { nameof(target.style.paddingTop), target.style.paddingTop = source.PaddingTop },
                { nameof(target.style.paddingRight), target.style.paddingRight = source.PaddingRight },
                { nameof(target.style.paddingBottom), target.style.paddingBottom = source.PaddingBottom },
                { nameof(target.style.alignSelf), target.style.alignSelf = (Align)source.AlignSelf.value },
                { nameof(target.style.unityTextAlign), target.style.unityTextAlign = (TextAnchor)source.UnityTextAlign.value },
                { nameof(target.style.unityFontStyleAndWeight), target.style.unityFontStyleAndWeight = (FontStyle)source.UnityFontStyleAndWeight.value },
                { nameof(target.style.fontSize), target.style.fontSize = source.FontSize },
                { nameof(target.style.whiteSpace), target.style.whiteSpace = (WhiteSpace)source.WhiteSpace.value },
                { nameof(target.style.color), target.style.color = source.Color },
                { nameof(target.style.backgroundColor), target.style.backgroundColor = source.BackgroundColor },
                { nameof(target.style.unityFont), target.style.unityFont = source.UnityFont },
                { nameof(target.style.unityBackgroundScaleMode), target.style.unityBackgroundScaleMode = (ScaleMode)source.UnityBackgroundScaleMode.value },
                { nameof(target.style.unityBackgroundImageTintColor), target.style.unityBackgroundImageTintColor = source.UnityBackgroundImageTintColor },
                { nameof(target.style.alignItems), target.style.alignItems = (Align)source.AlignItems.value },
                { nameof(target.style.alignContent), target.style.alignContent = (Align)source.AlignContent.value },
                { nameof(target.style.justifyContent), target.style.justifyContent = (Justify)source.JustifyContent.value },
                { nameof(target.style.borderLeftColor), target.style.borderLeftColor = source.BorderLeftColor },
                { nameof(target.style.borderRightColor), target.style.borderRightColor = source.BorderRightColor },
                { nameof(target.style.borderTopColor), target.style.borderTopColor = source.BorderTopColor },
                { nameof(target.style.borderBottomColor), target.style.borderBottomColor = source.BorderBottomColor },
                { nameof(target.style.borderLeftWidth), target.style.borderLeftWidth = source.BorderLeftWidth },
                { nameof(target.style.borderRightWidth), target.style.borderRightWidth = source.BorderRightWidth },
                { nameof(target.style.borderTopWidth), target.style.borderTopWidth = source.BorderTopWidth },
                { nameof(target.style.borderBottomWidth), target.style.borderBottomWidth = source.BorderBottomWidth },
                { nameof(target.style.borderTopLeftRadius), target.style.borderTopLeftRadius = source.BorderTopLeftRadius },
                { nameof(target.style.borderTopRightRadius), target.style.borderTopRightRadius = source.BorderTopRightRadius },
                { nameof(target.style.borderBottomLeftRadius), target.style.borderBottomLeftRadius = source.BorderBottomLeftRadius },
                { nameof(target.style.borderBottomRightRadius), target.style.borderBottomRightRadius = source.BorderBottomRightRadius },
                { nameof(target.style.opacity), target.style.opacity = source.Opacity.value },
                { nameof(target.style.visibility), target.style.visibility = (Visibility)source.Visibility.value },
                { nameof(target.style.display), target.style.display = (DisplayStyle)source.Display.value }
            };

            //styleValues.Add(nameof(target.style. ),target.style.left = source.left);
            //styleValues.Add(nameof(target.style. ),target.style.top = source.top);
            //styleValues.Add(nameof(target.style. ),target.style.right = source.right);
            //styleValues.Add(nameof(target.style. ),target.style.bottom = source.bottom);
            //styleValues.Add(nameof(target.style. ),target.style.position = source.position);
            //styleValues.Add(nameof(target.style. ),target.style.unitySliceLeft = source.unitySliceLeft);
            //styleValues.Add(nameof(target.style. ),target.style.unitySliceTop = source.unitySliceTop);
            //styleValues.Add(nameof(target.style. ),target.style.unitySliceRight = source.unitySliceRight);
            //styleValues.Add(nameof(target.style. ),target.style.unitySliceBottom = source.unitySliceBottom);

            if (!buildTable)
            {
                return(target);
            }

            var table = new TableBuilder();

            table.WithHeader("Target", "Name", "Type", "Value");
            styleValues.ForEach(x => { table.WithRow(source.SourceName, x.Key, x.Value.GetType().Name, x.Value.ToString()); });

            table.ToConsole();
            return(target);
        }