DatePickerText.TextMeshPro.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. namespace Bitsplash.DatePicker
  8. {
  9. partial class DatePickerText
  10. {
  11. partial void InnerSetMain()
  12. {
  13. mMain.TextTypeChanged -= MMain_TextTypeChanged;
  14. mMain.TextTypeChanged += MMain_TextTypeChanged;
  15. }
  16. partial void CheckTextMesh(ref bool res)
  17. {
  18. res = GetComponent<TMPro.TextMeshProUGUI>() != null;
  19. }
  20. partial void DestroyTextMesh()
  21. {
  22. CommonMethods.SafeDestroy(GetComponent<TMPro.TextMeshProUGUI>());
  23. }
  24. partial void InnerVerifyTextObject()
  25. {
  26. if (mMain.TextType == TextTypeEnum.StandardText)
  27. return;
  28. var obj = gameObject;
  29. if (contentGameObject != null)
  30. obj = contentGameObject.gameObject;
  31. var rect = obj.GetComponent<RectTransform>();
  32. if (rect != null)
  33. {
  34. Vector2 size = rect.sizeDelta;
  35. Vector2 anchor = rect.anchoredPosition;
  36. var tmpObj = CommonMethods.EnsureComponent<TMPro.TextMeshProUGUI>(obj, true);
  37. mTextObject = tmpObj;
  38. tmpObj.font = mMain.FontAsset;
  39. rect.anchoredPosition = anchor;
  40. rect.sizeDelta = size;
  41. }
  42. else
  43. Debug.LogWarning("object must have a rect transform attached to it in order to use DatePickerText");
  44. }
  45. partial void MediateTextMeshProText(string text)
  46. {
  47. var tmp = mTextObject as TMPro.TextMeshProUGUI;
  48. if (tmp != null)
  49. tmp.text = text;
  50. }
  51. partial void MediateTextMeshAlignment(TextAnchor alignment)
  52. {
  53. var tmp = mTextObject as TMPro.TextMeshProUGUI;
  54. if (tmp != null)
  55. {
  56. switch(alignment)
  57. {
  58. case TextAnchor.LowerCenter:
  59. tmp.alignment = TMPro.TextAlignmentOptions.Bottom;
  60. break;
  61. case TextAnchor.LowerLeft:
  62. tmp.alignment = TMPro.TextAlignmentOptions.BottomLeft;
  63. break;
  64. case TextAnchor.LowerRight:
  65. tmp.alignment = TMPro.TextAlignmentOptions.BottomRight;
  66. break;
  67. case TextAnchor.MiddleCenter:
  68. tmp.alignment = TMPro.TextAlignmentOptions.Center;
  69. break;
  70. case TextAnchor.MiddleLeft:
  71. tmp.alignment = TMPro.TextAlignmentOptions.Left;
  72. break;
  73. case TextAnchor.MiddleRight:
  74. tmp.alignment = TMPro.TextAlignmentOptions.Right;
  75. break;
  76. case TextAnchor.UpperCenter:
  77. tmp.alignment = TMPro.TextAlignmentOptions.Top;
  78. break;
  79. case TextAnchor.UpperLeft:
  80. tmp.alignment = TMPro.TextAlignmentOptions.TopLeft;
  81. break;
  82. case TextAnchor.UpperRight:
  83. tmp.alignment = TMPro.TextAlignmentOptions.TopRight;
  84. break;
  85. }
  86. }
  87. }
  88. partial void MediateTextMeshStyle(FontStyle style)
  89. {
  90. var tmp = mTextObject as TMPro.TextMeshProUGUI;
  91. if (tmp != null)
  92. {
  93. switch(style)
  94. {
  95. case FontStyle.Bold:
  96. tmp.fontStyle = TMPro.FontStyles.Bold;
  97. break;
  98. case FontStyle.BoldAndItalic:
  99. tmp.fontStyle = TMPro.FontStyles.Bold | TMPro.FontStyles.Italic;
  100. break;
  101. case FontStyle.Normal:
  102. tmp.fontStyle = TMPro.FontStyles.Normal;
  103. break;
  104. case FontStyle.Italic:
  105. tmp.fontStyle = TMPro.FontStyles.Italic;
  106. break;
  107. }
  108. }
  109. }
  110. partial void MediateTextMeshSize(int size)
  111. {
  112. var tmp = mTextObject as TMPro.TextMeshProUGUI;
  113. if (tmp != null)
  114. tmp.fontSize = size;
  115. }
  116. partial void MediateTextMeshProColor(Color color)
  117. {
  118. var tmp = mTextObject as TMPro.TextMeshProUGUI;
  119. if (tmp != null)
  120. tmp.color = color;
  121. }
  122. private void MMain_TextTypeChanged()
  123. {
  124. RecreateTextObject();
  125. }
  126. }
  127. }