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