You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.9 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace TMPro
  5. {
  6. public class FastAction
  7. {
  8. LinkedList<System.Action> delegates = new LinkedList<System.Action>();
  9. Dictionary<System.Action, LinkedListNode<System.Action>> lookup = new Dictionary<System.Action, LinkedListNode<System.Action>>();
  10. public void Add(System.Action rhs)
  11. {
  12. if (lookup.ContainsKey(rhs)) return;
  13. lookup[rhs] = delegates.AddLast(rhs);
  14. }
  15. public void Remove(System.Action rhs)
  16. {
  17. LinkedListNode<System.Action> node;
  18. if (lookup.TryGetValue(rhs, out node))
  19. {
  20. lookup.Remove(rhs);
  21. delegates.Remove(node);
  22. }
  23. }
  24. public void Call()
  25. {
  26. var node = delegates.First;
  27. while (node != null)
  28. {
  29. node.Value();
  30. node = node.Next;
  31. }
  32. }
  33. }
  34. public class FastAction<A>
  35. {
  36. LinkedList<System.Action<A>> delegates = new LinkedList<System.Action<A>>();
  37. Dictionary<System.Action<A>, LinkedListNode<System.Action<A>>> lookup = new Dictionary<System.Action<A>, LinkedListNode<System.Action<A>>>();
  38. public void Add(System.Action<A> rhs)
  39. {
  40. if (lookup.ContainsKey(rhs)) return;
  41. lookup[rhs] = delegates.AddLast(rhs);
  42. }
  43. public void Remove(System.Action<A> rhs)
  44. {
  45. LinkedListNode<System.Action<A>> node;
  46. if (lookup.TryGetValue(rhs, out node))
  47. {
  48. lookup.Remove(rhs);
  49. delegates.Remove(node);
  50. }
  51. }
  52. public void Call(A a)
  53. {
  54. var node = delegates.First;
  55. while (node != null)
  56. {
  57. node.Value(a);
  58. node = node.Next;
  59. }
  60. }
  61. }
  62. public class FastAction<A, B>
  63. {
  64. LinkedList<System.Action<A, B>> delegates = new LinkedList<System.Action<A, B>>();
  65. Dictionary<System.Action<A, B>, LinkedListNode<System.Action<A, B>>> lookup = new Dictionary<System.Action<A, B>, LinkedListNode<System.Action<A, B>>>();
  66. public void Add(System.Action<A, B> rhs)
  67. {
  68. if (lookup.ContainsKey(rhs)) return;
  69. lookup[rhs] = delegates.AddLast(rhs);
  70. }
  71. public void Remove(System.Action<A, B> rhs)
  72. {
  73. LinkedListNode<System.Action<A, B>> node;
  74. if (lookup.TryGetValue(rhs, out node))
  75. {
  76. lookup.Remove(rhs);
  77. delegates.Remove(node);
  78. }
  79. }
  80. public void Call(A a, B b)
  81. {
  82. var node = delegates.First;
  83. while (node != null)
  84. {
  85. node.Value(a, b);
  86. node = node.Next;
  87. }
  88. }
  89. }
  90. public class FastAction<A, B, C>
  91. {
  92. LinkedList<System.Action<A, B, C>> delegates = new LinkedList<System.Action<A, B, C>>();
  93. Dictionary<System.Action<A, B, C>, LinkedListNode<System.Action<A, B, C>>> lookup = new Dictionary<System.Action<A, B, C>, LinkedListNode<System.Action<A, B, C>>>();
  94. public void Add(System.Action<A, B, C> rhs)
  95. {
  96. if (lookup.ContainsKey(rhs)) return;
  97. lookup[rhs] = delegates.AddLast(rhs);
  98. }
  99. public void Remove(System.Action<A, B, C> rhs)
  100. {
  101. LinkedListNode<System.Action<A, B, C>> node;
  102. if (lookup.TryGetValue(rhs, out node))
  103. {
  104. lookup.Remove(rhs);
  105. delegates.Remove(node);
  106. }
  107. }
  108. public void Call(A a, B b, C c)
  109. {
  110. var node = delegates.First;
  111. while (node != null)
  112. {
  113. node.Value(a, b, c);
  114. node = node.Next;
  115. }
  116. }
  117. }
  118. }