Exemplo n.º 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);
            }
        }