using System; using UnityEngine; using UnityEngine.UI; namespace CIG { public class TextStyle { public TextStyle(string name, string textHexColor) { this.Name = name; this.TextHexColor = textHexColor; this.TextSize = null; this.Effect = TextStyle.TextEffect.None; } public TextStyle(string name, string textHexColor, int textSize) { this.Name = name; this.TextHexColor = textHexColor; this.TextSize = new int?(textSize); this.Effect = TextStyle.TextEffect.None; } public TextStyle(string name, string textHexColor, int? textSize, TextStyle.TextEffect effect, string effectHexColor, Vector2 effectDistance) { this.Name = name; this.TextHexColor = textHexColor; this.TextSize = textSize; this.Effect = effect; this.EffectHexColor = effectHexColor; this.EffectDistance = effectDistance; } public string Name { get; private set; } public string TextHexColor { get; private set; } public int? TextSize { get; private set; } public TextStyle.TextEffect Effect { get; private set; } public string EffectHexColor { get; private set; } public Vector2 EffectDistance { get; private set; } public void ApplyTo(Text text) { if (text == null) { UnityEngine.Debug.LogError("Text component is null."); } Color color; if (!ColorUtility.TryParseHtmlString(this.TextHexColor, out color)) { UnityEngine.Debug.LogErrorFormat("Cannot parse HEX: {0} to a Color.", new object[] { this.TextHexColor }); return; } text.color = color; if (this.TextSize != null) { text.fontSize = this.TextSize.Value; } } public void ApplyTo(Text text, Shadow effect) { this.ApplyTo(text); this.ApplyEffect(effect); } private void ApplyEffect(Shadow effect) { if (effect == null) { UnityEngine.Debug.LogError("Shadow component is null."); } Color effectColor; if (!ColorUtility.TryParseHtmlString(this.EffectHexColor, out effectColor)) { UnityEngine.Debug.LogErrorFormat("Cannot parse HEX: {0} to a Color.", new object[] { this.EffectHexColor }); return; } effect.effectColor = effectColor; effect.effectDistance = this.EffectDistance; } public enum TextEffect { None, Shadow, Outline } } }