public static string SaveCSS(GUIStyle style, GUIStyle empty = null, bool asTag = true) { empty = empty ?? GUIStyle.none; var contents = Style.contents; var styleName = asTag ? style.name : "." + style.name; contents.Clear(); if (!style.border.Matches(empty.border)) { contents.AppendLine("\tborder : " + style.border.Serialize(" ")); } if (!style.margin.Matches(empty.margin)) { contents.AppendLine("\tmargin : " + style.margin.Serialize(" ")); } if (!style.padding.Matches(empty.padding)) { contents.AppendLine("\tpadding : " + style.padding.Serialize(" ")); } if (!style.overflow.Matches(empty.overflow)) { contents.AppendLine("\toverflow : " + style.overflow.Serialize(" ")); } if (style.font != empty.font) { contents.AppendLine("\tfont : " + style.font.name); } if (style.fontSize != empty.fontSize) { contents.AppendLine("\tfont-size : " + style.fontSize); } if (style.fontStyle != empty.fontStyle) { contents.AppendLine("\tfont-style : " + style.fontStyle.ToName().ToCamelCase()); } if (style.alignment != empty.alignment) { contents.AppendLine("\talignment : " + style.alignment.ToName().ToCamelCase()); } if (style.wordWrap != empty.wordWrap) { contents.AppendLine("\tword-wrap : " + style.wordWrap); } if (style.richText != empty.richText) { contents.AppendLine("\trich-text : " + style.richText); } if (style.clipping != empty.clipping) { contents.AppendLine("\ttext-clipping : " + style.clipping.ToName().ToCamelCase()); } if (style.imagePosition != empty.imagePosition) { contents.AppendLine("\timage-position : " + style.imagePosition.ToName().ToCamelCase()); } if (!style.contentOffset.Equals(empty.contentOffset)) { contents.AppendLine("\tcontent-offset : " + style.contentOffset.x + " " + style.contentOffset.y); } if (style.fixedWidth != empty.fixedWidth) { contents.AppendLine("\tfixed-width : " + style.fixedWidth); } if (style.fixedHeight != empty.fixedHeight) { contents.AppendLine("\tfixed-height : " + style.fixedHeight); } if (style.stretchWidth != empty.stretchWidth) { contents.AppendLine("\tstretch-width : " + style.stretchWidth); } if (style.stretchHeight != empty.stretchHeight) { contents.AppendLine("\tstretch-height : " + style.stretchHeight); } if (contents.Length > 0) { contents.Insert(0, styleName + "{\n"); contents.AppendLine("}"); } foreach (var item in style.GetVariables <GUIStyleState>(null, ObjectExtension.publicFlags)) { var state = item.Value; bool hasBackground = !state.background.IsNull(); bool hasTextColor = state.textColor != empty.normal.textColor; if (!hasBackground && !hasTextColor) { continue; } contents.AppendLine(styleName + ":" + item.Key + "{"); if (hasBackground) { contents.AppendLine("\tbackground : " + state.background.name); } if (hasTextColor) { contents.AppendLine("\ttext-color : " + state.textColor.ToHex(false)); } contents.AppendLine("}"); } return(contents.ToString().Replace("True", "true").Replace("False", "false")); }