TMPro_EventManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. namespace TMPro
  4. {
  5. public enum Compute_DistanceTransform_EventTypes { Processing, Completed };
  6. public static class TMPro_EventManager
  7. {
  8. public static readonly FastAction<object, Compute_DT_EventArgs> COMPUTE_DT_EVENT = new FastAction<object, Compute_DT_EventArgs>();
  9. // Event & Delegate used to notify TextMesh Pro objects that Material properties have been changed.
  10. public static readonly FastAction<bool, Material> MATERIAL_PROPERTY_EVENT = new FastAction<bool, Material>();
  11. public static readonly FastAction<bool, TMP_FontAsset> FONT_PROPERTY_EVENT = new FastAction<bool, TMP_FontAsset>();
  12. public static readonly FastAction<bool, Object> SPRITE_ASSET_PROPERTY_EVENT = new FastAction<bool, Object>();
  13. public static readonly FastAction<bool, TextMeshPro> TEXTMESHPRO_PROPERTY_EVENT = new FastAction<bool, TextMeshPro>();
  14. public static readonly FastAction<GameObject, Material, Material> DRAG_AND_DROP_MATERIAL_EVENT = new FastAction<GameObject, Material, Material>();
  15. public static readonly FastAction<bool> TEXT_STYLE_PROPERTY_EVENT = new FastAction<bool>();
  16. public static readonly FastAction<TMP_ColorGradient> COLOR_GRADIENT_PROPERTY_EVENT = new FastAction<TMP_ColorGradient>();
  17. public static readonly FastAction TMP_SETTINGS_PROPERTY_EVENT = new FastAction();
  18. public static readonly FastAction RESOURCE_LOAD_EVENT = new FastAction();
  19. public static readonly FastAction<bool, TextMeshProUGUI> TEXTMESHPRO_UGUI_PROPERTY_EVENT = new FastAction<bool, TextMeshProUGUI>();
  20. public static readonly FastAction OnPreRenderObject_Event = new FastAction();
  21. public static readonly FastAction<Object> TEXT_CHANGED_EVENT = new FastAction<Object>();
  22. //public static readonly FastAction WILL_RENDER_CANVASES = new FastAction();
  23. //static TMPro_EventManager()
  24. //{
  25. // // Register to the willRenderCanvases callback once
  26. // // then the WILL_RENDER_CANVASES FastAction will handle the rest
  27. // Canvas.willRenderCanvases += WILL_RENDER_CANVASES.Call;
  28. //}
  29. public static void ON_PRE_RENDER_OBJECT_CHANGED()
  30. {
  31. OnPreRenderObject_Event.Call();
  32. }
  33. public static void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
  34. {
  35. MATERIAL_PROPERTY_EVENT.Call(isChanged, mat);
  36. }
  37. public static void ON_FONT_PROPERTY_CHANGED(bool isChanged, TMP_FontAsset font)
  38. {
  39. FONT_PROPERTY_EVENT.Call(isChanged, font);
  40. }
  41. public static void ON_SPRITE_ASSET_PROPERTY_CHANGED(bool isChanged, Object obj)
  42. {
  43. SPRITE_ASSET_PROPERTY_EVENT.Call(isChanged, obj);
  44. }
  45. public static void ON_TEXTMESHPRO_PROPERTY_CHANGED(bool isChanged, TextMeshPro obj)
  46. {
  47. TEXTMESHPRO_PROPERTY_EVENT.Call(isChanged, obj);
  48. }
  49. public static void ON_DRAG_AND_DROP_MATERIAL_CHANGED(GameObject sender, Material currentMaterial, Material newMaterial)
  50. {
  51. DRAG_AND_DROP_MATERIAL_EVENT.Call(sender, currentMaterial, newMaterial);
  52. }
  53. public static void ON_TEXT_STYLE_PROPERTY_CHANGED(bool isChanged)
  54. {
  55. TEXT_STYLE_PROPERTY_EVENT.Call(isChanged);
  56. }
  57. public static void ON_COLOR_GRAIDENT_PROPERTY_CHANGED(TMP_ColorGradient gradient)
  58. {
  59. COLOR_GRADIENT_PROPERTY_EVENT.Call(gradient);
  60. }
  61. public static void ON_TEXT_CHANGED(Object obj)
  62. {
  63. TEXT_CHANGED_EVENT.Call(obj);
  64. }
  65. public static void ON_TMP_SETTINGS_CHANGED()
  66. {
  67. TMP_SETTINGS_PROPERTY_EVENT.Call();
  68. }
  69. public static void ON_RESOURCES_LOADED()
  70. {
  71. RESOURCE_LOAD_EVENT.Call();
  72. }
  73. public static void ON_TEXTMESHPRO_UGUI_PROPERTY_CHANGED(bool isChanged, TextMeshProUGUI obj)
  74. {
  75. TEXTMESHPRO_UGUI_PROPERTY_EVENT.Call(isChanged, obj);
  76. }
  77. //public static void ON_BASE_MATERIAL_CHANGED(Material mat)
  78. //{
  79. // BASE_MATERIAL_EVENT.Call(mat);
  80. //}
  81. //public static void ON_PROGRESSBAR_UPDATE(Progress_Bar_EventTypes event_type, Progress_Bar_EventArgs eventArgs)
  82. //{
  83. // if (PROGRESS_BAR_EVENT != null)
  84. // PROGRESS_BAR_EVENT(event_type, eventArgs);
  85. //}
  86. public static void ON_COMPUTE_DT_EVENT(object Sender, Compute_DT_EventArgs e)
  87. {
  88. COMPUTE_DT_EVENT.Call(Sender, e);
  89. }
  90. }
  91. public class Compute_DT_EventArgs
  92. {
  93. public Compute_DistanceTransform_EventTypes EventType;
  94. public float ProgressPercentage;
  95. public Color[] Colors;
  96. public Compute_DT_EventArgs(Compute_DistanceTransform_EventTypes type, float progress)
  97. {
  98. EventType = type;
  99. ProgressPercentage = progress;
  100. }
  101. public Compute_DT_EventArgs(Compute_DistanceTransform_EventTypes type, Color[] colors)
  102. {
  103. EventType = type;
  104. Colors = colors;
  105. }
  106. }
  107. }