// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved. // This code can only be used under the standard Unity Asset Store End User License Agreement // A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms using Doozy.Runtime.Colors; using Doozy.Runtime.Common.Extensions; using UnityEngine; // ReSharper disable StringLiteralTypo namespace Doozy.Runtime.Common.Utils { /// /// Class that holds a collection of useful methods to show code snippets in TextMeshProUGUI components. /// It's useful to show in an example scene the code that is used in a specific example. /// public static class CodeExampleUtils { /// Wrap the given text in a color tag with the given color type /// Text to colorize /// ColorType /// Colorized text public static string Colorize(string text, Colors.ColorType colorType) => text?.Colorize(Colors.GetColor(colorType)); /// Wrap the given text in a color tag used for punctuation /// Text to colorize /// Colorized text public static string IsPunctuation(string text) => Colorize(text, Colors.ColorType.Punctuation); /// Wrap the given text in a color tag used for numbers /// Text to colorize /// Colorized text public static string IsNumber(string text) => Colorize(text, Colors.ColorType.Number); /// Wrap the given text in a color tag used for strings /// Text to colorize /// Colorized text public static string IsString(string text) => Colorize(text, Colors.ColorType.String); /// Wrap the given text in a color tag used for class names /// Text to colorize /// Colorized text public static string IsClassName(string text) => Colorize(text, Colors.ColorType.ClassName); /// Wrap the given text in a color tag used for function names /// Text to colorize /// Colorized text public static string IsFunctionName(string text) => Colorize(text, Colors.ColorType.FunctionName); /// Wrap the given text in a color tag used for property names /// Text to colorize /// Colorized text public static string IsProperty(string text) => Colorize(text, Colors.ColorType.PropertyName); /// Wrap the given text in a color tag used for property values /// Text to colorize /// Colorized text public static string IsPropertyValue(string text) => Colorize(text, Colors.ColorType.PropertyValue); /// Wrap the given text in a color tag used for comments /// Text to colorize /// Colorized text public static string IsComment(string text) => Colorize(text, Colors.ColorType.Comment); /// /// Colors used for the code example text. /// These colors are used to colorize the code example text by wrapping it in a color tag based on the color type. /// Types of colors are the most common ones used in code examples. /// public static class Colors { /// Describes the type of color used for the code example text public enum ColorType { Punctuation, Number, String, ClassName, FunctionName, PropertyName, PropertyValue, Comment } /// Get the corresponding color for the given ColorType /// ColorType /// Color public static Color GetColor(ColorType colorType) { switch (colorType) { case ColorType.Punctuation: return punctuationColor; case ColorType.Number: return numberColor; case ColorType.String: return stringColor; case ColorType.ClassName: return classNameColor; case ColorType.FunctionName: return functionNameColor; case ColorType.PropertyName: return propertyNameColor; case ColorType.PropertyValue: return propertyValueColor; case ColorType.Comment: return commentColor; default: return Color.white; } } private static Color s_punctuationColor; /// Color used for punctuation public static Color punctuationColor => s_punctuationColor != default ? s_punctuationColor : s_punctuationColor = new Color().FromHEX("BDBDBD"); private static Color s_numberColor; /// Color used for numbers public static Color numberColor => s_numberColor != default ? s_numberColor : s_numberColor = new Color().FromHEX("ED94C0"); private static Color s_stringColor; /// Color used for strings public static Color stringColor => s_stringColor != default ? s_stringColor : s_stringColor = new Color().FromHEX("C9A26D"); private static Color s_classNameColor; /// Color used for class names public static Color classNameColor => s_classNameColor != default ? s_classNameColor : s_classNameColor = new Color().FromHEX("C191FF"); private static Color s_functionNameColor; /// Color used for function and method names public static Color functionNameColor => s_functionNameColor != default ? s_functionNameColor : s_functionNameColor = new Color().FromHEX("39CC8F"); private static Color s_propertyNameColor; /// Color used for property names public static Color propertyNameColor => s_propertyNameColor != default ? s_propertyNameColor : s_propertyNameColor = new Color().FromHEX("6C95EB"); private static Color s_propertyValueColor; /// Color used for property values public static Color propertyValueColor => s_propertyValueColor != default ? s_propertyValueColor : s_propertyValueColor = new Color().FromHEX("FFC66D"); private static Color s_commentColor; /// Color used for comments public static Color commentColor => s_commentColor != default ? s_commentColor : s_commentColor = new Color().FromHEX("85C46C"); } } }