コード例 #1
0
        internal void ApplyRule(StyleSheet registry, int specificity, StyleRule rule, StylePropertyID[] propertyIDs)
        {
            for (int i = 0; i < rule.properties.Length; i++)
            {
                UnityEngine.StyleSheets.StyleProperty styleProperty = rule.properties[i];
                StylePropertyID propertyID = propertyIDs[i];

                var handles = styleProperty.values;
                switch (propertyID)
                {
                case StylePropertyID.AlignContent:
                    registry.Apply(handles, specificity, ref alignContent, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.AlignItems:
                    registry.Apply(handles, specificity, ref alignItems, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.AlignSelf:
                    registry.Apply(handles, specificity, ref alignSelf, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.BackgroundImage:
                    registry.Apply(handles, specificity, ref backgroundImage, StyleSheetApplicator.ApplyImage);
                    break;

                case StylePropertyID.Flex:
                    registry.ApplyShorthand(handles, specificity, this, StyleSheetApplicator.ApplyFlexShorthand);
                    break;

                case StylePropertyID.FlexBasis:
                    registry.Apply(handles, specificity, ref flexBasis, StyleSheetApplicator.ApplyFloatOrKeyword);
                    break;

                case StylePropertyID.FlexGrow:
                    registry.Apply(handles, specificity, ref flexGrow, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.FlexShrink:
                    registry.Apply(handles, specificity, ref flexShrink, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Font:
                    registry.Apply(handles, specificity, ref font, StyleSheetApplicator.ApplyFont);
                    break;

                case StylePropertyID.FontSize:
                    registry.Apply(handles, specificity, ref fontSize, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.FontStyleAndWeight:
                    registry.Apply(handles, specificity, ref fontStyleAndWeight, StyleSheetApplicator.ApplyEnum <FontStyle>);
                    break;

                case StylePropertyID.FlexDirection:
                    registry.Apply(handles, specificity, ref flexDirection, StyleSheetApplicator.ApplyEnum <FlexDirection>);
                    break;

                case StylePropertyID.FlexWrap:
                    registry.Apply(handles, specificity, ref flexWrap, StyleSheetApplicator.ApplyEnum <Wrap>);
                    break;

                case StylePropertyID.Height:
                    registry.Apply(handles, specificity, ref height, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.JustifyContent:
                    registry.Apply(handles, specificity, ref justifyContent, StyleSheetApplicator.ApplyEnum <Justify>);
                    break;

                case StylePropertyID.MarginLeft:
                    registry.Apply(handles, specificity, ref marginLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginTop:
                    registry.Apply(handles, specificity, ref marginTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginRight:
                    registry.Apply(handles, specificity, ref marginRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginBottom:
                    registry.Apply(handles, specificity, ref marginBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MaxHeight:
                    registry.Apply(handles, specificity, ref maxHeight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MaxWidth:
                    registry.Apply(handles, specificity, ref maxWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MinHeight:
                    registry.Apply(handles, specificity, ref minHeight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MinWidth:
                    registry.Apply(handles, specificity, ref minWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Overflow:
                    registry.Apply(handles, specificity, ref overflow, StyleSheetApplicator.ApplyEnum <Overflow>);
                    break;

                case StylePropertyID.PaddingLeft:
                    registry.Apply(handles, specificity, ref paddingLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingTop:
                    registry.Apply(handles, specificity, ref paddingTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingRight:
                    registry.Apply(handles, specificity, ref paddingRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingBottom:
                    registry.Apply(handles, specificity, ref paddingBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Position:
                    registry.Apply(handles, specificity, ref positionType, StyleSheetApplicator.ApplyEnum <Position>);
                    break;

                case StylePropertyID.PositionType:
                    registry.Apply(handles, specificity, ref positionType, StyleSheetApplicator.ApplyEnum <PositionType>);
                    break;

                case StylePropertyID.PositionTop:
                    registry.Apply(handles, specificity, ref positionTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionBottom:
                    registry.Apply(handles, specificity, ref positionBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionLeft:
                    registry.Apply(handles, specificity, ref positionLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionRight:
                    registry.Apply(handles, specificity, ref positionRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.UnityTextAlign:
                    registry.Apply(handles, specificity, ref unityTextAlign, StyleSheetApplicator.ApplyEnum <TextAnchor>);
                    break;

                case StylePropertyID.TextClipping:
                    registry.Apply(handles, specificity, ref textClipping, StyleSheetApplicator.ApplyEnum <TextClipping>);
                    break;

                case StylePropertyID.Color:
                    registry.Apply(handles, specificity, ref color, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.Width:
                    registry.Apply(handles, specificity, ref width, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.WordWrap:
                    registry.Apply(handles, specificity, ref wordWrap, StyleSheetApplicator.ApplyBool);
                    break;

                case StylePropertyID.BackgroundColor:
                    registry.Apply(handles, specificity, ref backgroundColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.BackgroundScaleMode:
                    registry.Apply(handles, specificity, ref backgroundScaleMode, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.BorderColor:
                    registry.Apply(handles, specificity, ref borderColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.BorderLeftWidth:
                    registry.Apply(handles, specificity, ref borderLeftWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopWidth:
                    registry.Apply(handles, specificity, ref borderTopWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderRightWidth:
                    registry.Apply(handles, specificity, ref borderRightWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomWidth:
                    registry.Apply(handles, specificity, ref borderBottomWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopLeftRadius:
                    registry.Apply(handles, specificity, ref borderTopLeftRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopRightRadius:
                    registry.Apply(handles, specificity, ref borderTopRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomRightRadius:
                    registry.Apply(handles, specificity, ref borderBottomRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomLeftRadius:
                    registry.Apply(handles, specificity, ref borderBottomLeftRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Cursor:
                    registry.Apply(handles, specificity, ref cursor, StyleSheetApplicator.ApplyCursor);
                    break;

                case StylePropertyID.SliceLeft:
                    registry.Apply(handles, specificity, ref sliceLeft, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceTop:
                    registry.Apply(handles, specificity, ref sliceTop, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceRight:
                    registry.Apply(handles, specificity, ref sliceRight, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceBottom:
                    registry.Apply(handles, specificity, ref sliceBottom, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.Opacity:
                    registry.Apply(handles, specificity, ref opacity, StyleSheetApplicator.ApplyFloat);
                    break;

                // Shorthand values
                case StylePropertyID.BorderRadius:
                    registry.Apply(handles, specificity, ref borderTopLeftRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderTopRightRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderBottomLeftRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderBottomRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Visibility:
                    registry.Apply(handles, specificity, ref visibility, StyleSheetApplicator.ApplyEnum <Visibility>);
                    break;

                case StylePropertyID.Custom:
                    if (m_CustomProperties == null)
                    {
                        m_CustomProperties = new Dictionary <string, CustomProperty>();
                    }
                    CustomProperty customProp = default(CustomProperty);
                    if (!m_CustomProperties.TryGetValue(styleProperty.name, out customProp) || specificity >= customProp.specificity)
                    {
                        customProp.handles     = handles;
                        customProp.data        = registry;
                        customProp.specificity = specificity;
                        m_CustomProperties[styleProperty.name] = customProp;
                    }
                    break;

                default:
                    throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", propertyID));
                }
            }
        }