StyleValueHandle AddTypedValue <T>(T value, StyleValueType type)
        {
            switch (type)
            {
            case StyleValueType.Keyword:
                return(styleSheet.AddValue(styleProperty, (StyleValueKeyword)(object)value));

            case StyleValueType.Float:
                return(styleSheet.AddValue(styleProperty, (float)(object)value));

            case StyleValueType.Dimension:
                return(styleSheet.AddValue(styleProperty, (Dimension)(object)value));

            case StyleValueType.Color:
                return(styleSheet.AddValue(styleProperty, (Color)(object)value));

            case StyleValueType.ResourcePath:
                return(styleSheet.AddValue(styleProperty, (string)(object)value));

            case StyleValueType.AssetReference:
                return(styleSheet.AddValue(styleProperty, (UnityEngine.Object)(object) value));

            case StyleValueType.Enum:
            {
                if (value is string strValue)
                {
                    // Add value data to data array.
                    var index = styleSheet.AddValueToArray(strValue);

                    // Add value object to property.
                    return(styleSheet.AddValueHandle(styleProperty, index, StyleValueType.Enum));
                }
                return(styleSheet.AddValue(styleProperty, (Enum)(object)value));
            }

            case StyleValueType.String:
                return(styleSheet.AddValue(styleProperty, (string)(object)value));

            case StyleValueType.MissingAssetReference:
                return(styleSheet.AddValue(styleProperty, (string)(object)value));

            case StyleValueType.ScalableImage:
            // Not actually supported
            //return styleSheet.AddValue(styleProperty, (ScalableImage)(object) value);
            // These are not "values".
            case StyleValueType.Invalid:
            case StyleValueType.Variable:
            case StyleValueType.Function:
            case StyleValueType.CommaSeparator:
            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Beispiel #2
0
        internal static StyleValueHandle[] AddVariable(this StyleSheet styleSheet, StyleProperty property, string value)
        {
            // Undo/Redo
            Undo.RegisterCompleteObjectUndo(styleSheet, BuilderConstants.ChangeUIStyleValueUndoMessage);

            // Add the function name
            var funcHandle = styleSheet.AddValueHandle(property, (int)StyleValueFunction.Var, StyleValueType.Function);

            // Add the argument count
            var index     = styleSheet.AddValueToArray(1);
            var argHandle = styleSheet.AddValueHandle(property, index, StyleValueType.Float);

            // Add the variable name
            index = styleSheet.AddValueToArray(value);
            var newValue = styleSheet.AddValueHandle(property, index, StyleValueType.Variable);

            return(new StyleValueHandle[] { funcHandle, argHandle, newValue });
        }
Beispiel #3
0
        internal static StyleValueHandle AddValue(this StyleSheet styleSheet, StyleProperty property, Color value)
        {
            // Undo/Redo
            Undo.RegisterCompleteObjectUndo(styleSheet, BuilderConstants.ChangeUIStyleValueUndoMessage);

            // Add value data to data array.
            var index = styleSheet.AddValueToArray(value);

            // Add value object to property.
            var newValue = styleSheet.AddValueHandle(property, index, StyleValueType.Color);

            return(newValue);
        }
Beispiel #4
0
        internal static StyleValueHandle AddValue(this StyleSheet styleSheet, StyleProperty property, string value)
        {
            // Undo/Redo
            Undo.RegisterCompleteObjectUndo(styleSheet, "Change UI Style Value");

            // Add value data to data array.
            var index = styleSheet.AddValueToArray(value);

            // Add value object to property.
            var newValue = styleSheet.AddValueHandle(property, index, StyleValueType.String);

            return(newValue);
        }
 public static void SwallowStyleRule(
     StyleSheet toStyleSheet, StyleRule toRule,
     StyleSheet fromStyleSheet, StyleRule fromRule)
 {
     // Add property values to sheet.
     foreach (var fromProperty in fromRule.properties)
     {
         var toProperty = toStyleSheet.AddProperty(toRule, fromProperty.name);
         for (int i = 0; i < fromProperty.values.Length; ++i)
         {
             var fromValueHandle = fromProperty.values[i];
             var toValueIndex    = toStyleSheet.SwallowStyleValue(fromStyleSheet, fromValueHandle);
             toStyleSheet.AddValueHandle(toProperty, toValueIndex, fromValueHandle.valueType);
         }
     }
 }
Beispiel #6
0
        internal static StyleValueHandle AddValue(this StyleSheet styleSheet, StyleProperty property, Object value)
        {
            // Undo/Redo
            Undo.RegisterCompleteObjectUndo(styleSheet, BuilderConstants.ChangeUIStyleValueUndoMessage);

            // Determine real asset type.
            var resourcePath   = BuilderAssetUtilities.GetResourcesPathForAsset(value);
            var styleValueType = string.IsNullOrEmpty(resourcePath) ? StyleValueType.AssetReference : StyleValueType.ResourcePath;

            // Add value data to data array.
            var index = string.IsNullOrEmpty(resourcePath) ? styleSheet.AddValueToArray(value) : styleSheet.AddValueToArray(resourcePath);

            // Add value object to property.
            var newValue = styleSheet.AddValueHandle(property, index, styleValueType);

            return(newValue);
        }
Beispiel #7
0
        internal static StyleValueHandle AddValue(
            this StyleSheet styleSheet, StyleProperty property, Dimension value, string undoMessage = null)
        {
            // Undo/Redo
            if (string.IsNullOrEmpty(undoMessage))
            {
                undoMessage = BuilderConstants.ChangeUIStyleValueUndoMessage;
            }
            Undo.RegisterCompleteObjectUndo(styleSheet, undoMessage);

            // Add value data to data array.
            var index = styleSheet.AddValueToArray(value);

            // Add value object to property.
            var newValue = styleSheet.AddValueHandle(property, index, StyleValueType.Dimension);

            return(newValue);
        }