您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

102 行
2.3 KiB

  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace CIG
  5. {
  6. public class TextStyle
  7. {
  8. public TextStyle(string name, string textHexColor)
  9. {
  10. this.Name = name;
  11. this.TextHexColor = textHexColor;
  12. this.TextSize = null;
  13. this.Effect = TextStyle.TextEffect.None;
  14. }
  15. public TextStyle(string name, string textHexColor, int textSize)
  16. {
  17. this.Name = name;
  18. this.TextHexColor = textHexColor;
  19. this.TextSize = new int?(textSize);
  20. this.Effect = TextStyle.TextEffect.None;
  21. }
  22. public TextStyle(string name, string textHexColor, int? textSize, TextStyle.TextEffect effect, string effectHexColor, Vector2 effectDistance)
  23. {
  24. this.Name = name;
  25. this.TextHexColor = textHexColor;
  26. this.TextSize = textSize;
  27. this.Effect = effect;
  28. this.EffectHexColor = effectHexColor;
  29. this.EffectDistance = effectDistance;
  30. }
  31. public string Name { get; private set; }
  32. public string TextHexColor { get; private set; }
  33. public int? TextSize { get; private set; }
  34. public TextStyle.TextEffect Effect { get; private set; }
  35. public string EffectHexColor { get; private set; }
  36. public Vector2 EffectDistance { get; private set; }
  37. public void ApplyTo(Text text)
  38. {
  39. if (text == null)
  40. {
  41. UnityEngine.Debug.LogError("Text component is null.");
  42. }
  43. Color color;
  44. if (!ColorUtility.TryParseHtmlString(this.TextHexColor, out color))
  45. {
  46. UnityEngine.Debug.LogErrorFormat("Cannot parse HEX: {0} to a Color.", new object[]
  47. {
  48. this.TextHexColor
  49. });
  50. return;
  51. }
  52. text.color = color;
  53. if (this.TextSize != null)
  54. {
  55. text.fontSize = this.TextSize.Value;
  56. }
  57. }
  58. public void ApplyTo(Text text, Shadow effect)
  59. {
  60. this.ApplyTo(text);
  61. this.ApplyEffect(effect);
  62. }
  63. private void ApplyEffect(Shadow effect)
  64. {
  65. if (effect == null)
  66. {
  67. UnityEngine.Debug.LogError("Shadow component is null.");
  68. }
  69. Color effectColor;
  70. if (!ColorUtility.TryParseHtmlString(this.EffectHexColor, out effectColor))
  71. {
  72. UnityEngine.Debug.LogErrorFormat("Cannot parse HEX: {0} to a Color.", new object[]
  73. {
  74. this.EffectHexColor
  75. });
  76. return;
  77. }
  78. effect.effectColor = effectColor;
  79. effect.effectDistance = this.EffectDistance;
  80. }
  81. public enum TextEffect
  82. {
  83. None,
  84. Shadow,
  85. Outline
  86. }
  87. }
  88. }