Beispiel #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);
        }
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 });
        }
        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 #4
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 #5
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);
        }
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);
        }