-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericTest.cs
More file actions
executable file
·80 lines (67 loc) · 1.62 KB
/
Copy pathGenericTest.cs
File metadata and controls
executable file
·80 lines (67 loc) · 1.62 KB
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
using UnityEngine;
using System;
using System.Collections;
using NukeMessage;
using Pathfinding.Serialization.JsonFx;
namespace MyCollections
{
public delegate void ChangedEventHandler(object sender, Generic_Data data);
public class ListWithChangedEvent: ArrayList
{
// An event that clients can use to be notified whenever the
// elements of the list change.
public event ChangedEventHandler Changed;
// Invoke the Changed event; called whenever list changes
protected virtual void OnChanged(Generic_Data data)
{
if (Changed != null) Changed(this, data);
}
// Override some of the methods that can change the list;
// invoke event after each
public override int Add(object value)
{
int i = base.Add(value);
OnChanged((Generic_Data)value);
return i;
}
public override void Clear()
{
base.Clear();
OnChanged(new Generic_Data());
}
public override object this[int index]
{
set
{
base[index] = value;
OnChanged(new Generic_Data());
}
}
}
}
namespace GenericTest
{
using MyCollections;
using MsgHandler;
class EventListener
{
private ListWithChangedEvent List;
public EventListener(ListWithChangedEvent list)
{
List = list;
// Add "ListChanged" to the Changed event on "List".
List.Changed += new ChangedEventHandler(ListChanged);
}
// This will be called whenever the list changes.
private void ListChanged(object sender, Generic_Data data)
{
MsgHandler.OnRcvMsg(data);
}
public void Detach()
{
// Detach the event and delete the list
List.Changed -= new ChangedEventHandler(ListChanged);
List = null;
}
}
}