Example #1
0
        public static int SwallowStyleValue(this StyleSheet to, StyleSheet from, StyleValueHandle valueHandle)
        {
            var index = 0;

            switch (valueHandle.valueType)
            {
            case StyleValueType.Keyword:
                index = to.AddValueToArray(from.GetKeyword(valueHandle)); break;

            case StyleValueType.Float:
                index = to.AddValueToArray(from.GetFloat(valueHandle)); break;

            case StyleValueType.Dimension:
                index = to.AddValueToArray(from.GetDimension(valueHandle)); break;

            case StyleValueType.Color:
                index = to.AddValueToArray(from.GetColor(valueHandle)); break;

            case StyleValueType.String:
                index = to.AddValueToArray(from.GetString(valueHandle)); break;

            case StyleValueType.AssetReference:
                index = to.AddValueToArray(from.GetAsset(valueHandle)); break;

            case StyleValueType.ResourcePath:
                index = to.AddValueToArray(from.GetString(valueHandle)); break;

            case StyleValueType.Enum:
                index = to.AddValueToArray(from.GetEnum(valueHandle)); break;
            }

            return(index);
        }
        public static void TransferRulePropertiesToSelector(this StyleSheet toStyleSheet, StyleComplexSelector toSelector, StyleSheet fromStyleSheet, StyleRule fromRule)
        {
            foreach (var property in fromRule.properties)
            {
                var newProperty = toStyleSheet.AddProperty(toSelector, property.name);
                foreach (var value in property.values)
                {
                    switch (value.valueType)
                    {
                    case StyleValueType.Float: toStyleSheet.AddValue(newProperty, fromStyleSheet.GetFloat(value)); break;

#if UNITY_2019_3_OR_NEWER
                    case StyleValueType.Dimension: toStyleSheet.AddValue(newProperty, fromStyleSheet.GetDimension(value)); break;
#endif
                    case StyleValueType.Enum: toStyleSheet.AddValueAsEnum(newProperty, fromStyleSheet.GetEnum(value)); break;

                    case StyleValueType.String: toStyleSheet.AddValue(newProperty, fromStyleSheet.GetString(value)); break;

                    case StyleValueType.Color: toStyleSheet.AddValue(newProperty, fromStyleSheet.GetColor(value)); break;

                    case StyleValueType.AssetReference: toStyleSheet.AddValue(newProperty, fromStyleSheet.GetAsset(value)); break;

                    case StyleValueType.ResourcePath: toStyleSheet.AddValue(newProperty, fromStyleSheet.GetAsset(value)); break;

#if UNITY_2019_3_OR_NEWER // UNITY_BUILDER_VARIABLE_SUPPORT
                    case StyleValueType.Variable: toStyleSheet.AddVariable(newProperty, fromStyleSheet.GetString(value)); break;
#endif
                    }
                }
            }
            foreach (var property in fromRule.properties)
            {
                fromStyleSheet.RemoveProperty(fromRule, property);
            }
        }
Example #3
0
        public static BuilderTextShadow GetTextShadow(this StyleSheet styleSheet, StyleProperty styleProperty)
        {
            Dimension offsetX    = new Dimension(0f, Dimension.Unit.Pixel);
            Dimension offsetY    = new Dimension(0f, Dimension.Unit.Pixel);
            Dimension blurRadius = new Dimension(0f, Dimension.Unit.Pixel);
            var       color      = Color.clear;

            var valueCount = styleProperty.values.Length;

            if (valueCount >= 2)
            {
                int  i             = 0;
                var  valueType     = styleProperty.values[i].valueType;
                bool wasColorFound = false;
                if (valueType == StyleValueType.Color || valueType == StyleValueType.Enum)
                {
                    color         = styleSheet.GetColor(styleProperty.values[i++]);
                    wasColorFound = true;
                }

                if (i + 1 < valueCount)
                {
                    valueType = styleProperty.values[i].valueType;
                    var valueType2 = styleProperty.values[i + 1].valueType;
                    if (valueType == StyleValueType.Dimension && valueType2 == StyleValueType.Dimension)
                    {
                        var valueX = styleProperty.values[i++];
                        var valueY = styleProperty.values[i++];

                        offsetX = styleSheet.GetDimension(valueX);
                        offsetY = styleSheet.GetDimension(valueY);
                    }
                }

                if (i < valueCount)
                {
                    valueType = styleProperty.values[i].valueType;
                    if (valueType == StyleValueType.Dimension)
                    {
                        var valueBlur = styleProperty.values[i++];
                        blurRadius = styleSheet.GetDimension(valueBlur);
                    }
                    else if (valueType == StyleValueType.Color || valueType == StyleValueType.Enum)
                    {
                        if (!wasColorFound)
                        {
                            color = styleSheet.GetColor(styleProperty.values[i]);
                        }
                    }
                }

                if (i < valueCount)
                {
                    valueType = styleProperty.values[i].valueType;
                    if (valueType == StyleValueType.Color || valueType == StyleValueType.Enum)
                    {
                        if (!wasColorFound)
                        {
                            color = styleSheet.GetColor(styleProperty.values[i]);
                        }
                    }
                }
            }

            return(new BuilderTextShadow
            {
                offsetX = offsetX,
                offsetY = offsetY,
                blurRadius = blurRadius,
                color = color
            });
        }