コード例 #1
0
            public bool CompareTo(Value v)
            {
                if (ValueType != v.ValueType)
                {
                    return(false);
                }

                switch (ValueType)
                {
                case StyleValueType.Color:
                    return(GUISkinCompare.CompareTo(v.AsColor(), AsColor()));

                case StyleValueType.Float:
                    return(GUISkinCompare.CompareTo(v.AsFloat(), AsFloat()));

                case StyleValueType.Keyword:
                    return(v.AsKeyword() == AsKeyword());

                case StyleValueType.Enum:
                case StyleValueType.ResourcePath:
                case StyleValueType.String:
                    return(v.AsString() == AsString());
                }
                return(true);
            }
コード例 #2
0
        private static void AddState(StyleSheetBuilderHelper helper, GUIStyleState state, GUIStyleState defaultStyle)
        {
            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(state.textColor, defaultStyle.textColor))
            {
                helper.AddProperty("color", state.textColor, "GUIState.textColor");
            }

            if (helper.options.exportDefaultValues || state.background != defaultStyle.background)
            {
                AddPropertyResource(helper, ConverterUtils.k_BackgroundImage, state.background, "GUIState.background");
            }

            var scaledBackground        = state.scaledBackgrounds.Length > 0 ? state.scaledBackgrounds[0] : null;
            var defaultScaledBackground = defaultStyle.scaledBackgrounds.Length > 0 ? defaultStyle.scaledBackgrounds[0] : null;

            if (helper.options.exportDefaultValues || scaledBackground != defaultScaledBackground)
            {
                AddPropertyResource(helper, ConverterUtils.k_ScaledBackground, scaledBackground, "GUIState.scaledBackgrounds");
            }
        }
コード例 #3
0
        // Public API to serialize GUIStyle and GUISkin
        public static void AddStyle(StyleSheetBuilderHelper helper, string name, GUIStyle style, GUIStyle defaultStyle = null, string extendName = null)
        {
            defaultStyle = defaultStyle ?? GUIStyle.none;
            // All common Style property
            helper.BeginRule();

            using (helper.builder.BeginComplexSelector(0))
            {
                // Construct rule according to the GUIStyle -> is it custom? is it bound on a type?
                helper.builder.AddSimpleSelector(new[] { ConverterUtils.CreateSelectorPart(name) }, StyleSelectorRelationship.None);
            }

            if (!string.IsNullOrEmpty(extendName))
            {
                helper.AddPropertyString(ConverterUtils.k_Extend, extendName);
            }

            // Loop for each GUIStyle property
            if (helper.options.exportDefaultValues || style.alignment != defaultStyle.alignment)
            {
                helper.AddProperty(ConverterUtils.k_TextAlignment, ConverterUtils.ToUssString(style.alignment), "GUIStyle.alignment");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.border, defaultStyle.border))
            {
                AddProperty(helper, ConverterUtils.k_Border, "", style.border, defaultStyle.border, "GUIStyle.border");
            }

            if (helper.options.exportDefaultValues || style.clipping != defaultStyle.clipping)
            {
                helper.AddProperty(ConverterUtils.k_Clipping, ConverterUtils.ToUssString(style.clipping), "GUIStyle.clipping");
            }

            if (helper.options.exportDefaultValues || style.contentOffset != defaultStyle.contentOffset)
            {
                helper.AddProperty(ConverterUtils.k_ContentOffset, style.contentOffset, "GUIStyle.contentOffset");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.fixedHeight, defaultStyle.fixedHeight))
            {
                helper.AddProperty(ConverterUtils.k_Height, style.fixedHeight, "GUIStyle.fixedHeight");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.fixedWidth, defaultStyle.fixedWidth))
            {
                helper.AddProperty(ConverterUtils.k_Width, style.fixedWidth, "GUIStyle.fixedWidth");
            }

            if (helper.options.exportDefaultValues || style.font != defaultStyle.font)
            {
                AddPropertyResource(helper, ConverterUtils.k_Font, style.font, "GUIStyle.font");
            }

            if (helper.options.exportDefaultValues || style.fontSize != defaultStyle.fontSize)
            {
                helper.AddProperty(ConverterUtils.k_FontSize, style.fontSize, "GUIStyle.fontSize");
            }

            if (helper.options.exportDefaultValues || style.fontStyle != defaultStyle.fontStyle)
            {
                AddProperty(helper, style.fontStyle, "GUIStyle.fontSize");
            }

            if (helper.options.exportDefaultValues || style.imagePosition != defaultStyle.imagePosition)
            {
                helper.AddProperty(ConverterUtils.k_ImagePosition, ConverterUtils.ToUssString(style.imagePosition), "GUIStyle.imagePosition");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.margin, defaultStyle.margin))
            {
                AddProperty(helper, ConverterUtils.k_Margin, null, style.margin, defaultStyle.margin, "GUIStyle.margin");
            }

            // Always export name:
            helper.AddPropertyString(ConverterUtils.k_Name, style.name, "GUIStyle.name");

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.overflow, defaultStyle.overflow))
            {
                AddProperty(helper, ConverterUtils.k_Overflow, null, style.overflow, defaultStyle.overflow, "GUIStyle.overflow");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.padding, defaultStyle.padding))
            {
                AddProperty(helper, ConverterUtils.k_Padding, null, style.padding, defaultStyle.padding, "GUIStyle.padding");
            }

            if (helper.options.exportDefaultValues || style.richText != defaultStyle.richText)
            {
                helper.AddProperty(ConverterUtils.k_RichText, style.richText, "GUIStyle.richText");
            }

            if (helper.options.exportDefaultValues || style.stretchHeight != defaultStyle.stretchHeight)
            {
                helper.AddProperty(ConverterUtils.k_StretchHeight, style.stretchHeight, "GUIStyle.stretchHeight");
            }

            if (helper.options.exportDefaultValues || style.stretchWidth != defaultStyle.stretchWidth)
            {
                helper.AddProperty(ConverterUtils.k_StretchWidth, style.stretchWidth, "GUIStyle.stretchWidth");
            }

            if (helper.options.exportDefaultValues || style.wordWrap != defaultStyle.wordWrap)
            {
                helper.AddProperty(ConverterUtils.k_WordWrap, style.wordWrap, "GUIStyle.wordWrap");
            }

            // Add Normal state properties
            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.normal, defaultStyle.normal))
            {
                AddState(helper, style.normal, defaultStyle.normal);
            }

            helper.EndRule();

            // Add one rule for each GUIStyleState (other than normal)
            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.active, defaultStyle.active))
            {
                AddState(helper, name, style.active, "active", defaultStyle.active);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.focused, defaultStyle.focused))
            {
                AddState(helper, name, style.focused, "focused", defaultStyle.focused);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.hover, defaultStyle.hover))
            {
                AddState(helper, name, style.hover, "hover", defaultStyle.hover);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onActive, defaultStyle.onActive))
            {
                AddState(helper, name, style.onActive, "onActive", defaultStyle.onActive);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onFocused, defaultStyle.onFocused))
            {
                AddState(helper, name, style.onFocused, "onFocused", defaultStyle.onFocused);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onHover, defaultStyle.onHover))
            {
                AddState(helper, name, style.onHover, "onHover", defaultStyle.onHover);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onNormal, defaultStyle.onNormal))
            {
                AddState(helper, name, style.onNormal, "onNormal", defaultStyle.onNormal);
            }
        }
コード例 #4
0
        private bool CompareProperty(StyleProperty p1, StyleProperty p2)
        {
            if (p1.values.Length != p2.values.Length)
            {
                return(false);
            }

            for (var i = 0; i < p1.values.Length; i++)
            {
                var v1 = p1.values[i];
                var v2 = p2.values[i];

                if (v1.valueType != v2.valueType)
                {
                    return(false);
                }

                switch (v1.valueType)
                {
                case StyleValueType.Color:
                    var c1 = s1Cache.sheet.ReadColor(v1);
                    var c2 = s2Cache.sheet.ReadColor(v2);
                    if (!GUISkinCompare.CompareTo(c1, c2))
                    {
                        return(false);
                    }

                    break;

                case StyleValueType.Enum:
                    var e1 = s1Cache.sheet.ReadEnum(v1);
                    var e2 = s2Cache.sheet.ReadEnum(v2);
                    if (e1 != e2)
                    {
                        return(false);
                    }

                    break;

                case StyleValueType.Float:
                    var f1 = s1Cache.sheet.ReadFloat(v1);
                    var f2 = s2Cache.sheet.ReadFloat(v2);
                    if (!GUISkinCompare.CompareTo(f1, f2))
                    {
                        return(false);
                    }

                    break;

                case StyleValueType.Keyword:
                    var k1 = s1Cache.sheet.ReadKeyword(v1);
                    var k2 = s2Cache.sheet.ReadKeyword(v2);
                    if (k1 != k2)
                    {
                        return(false);
                    }
                    break;

                case StyleValueType.ResourcePath:
                    var rp1 = s1Cache.sheet.ReadResourcePath(v1);
                    var rp2 = s2Cache.sheet.ReadResourcePath(v2);
                    if (rp1 != rp2)
                    {
                        return(false);
                    }
                    break;

                case StyleValueType.String:
                    var s1 = s1Cache.sheet.ReadString(v1);
                    var s2 = s2Cache.sheet.ReadString(v2);
                    if (s1 != s2)
                    {
                        return(false);
                    }
                    break;
                }
            }

            return(true);
        }