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