forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyncList`1.cs
More file actions
237 lines (211 loc) · 6.14 KB
/
SyncList`1.cs
File metadata and controls
237 lines (211 loc) · 6.14 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Decompiled with JetBrains decompiler
// Type: UnityEngine.Networking.SyncList`1
// Assembly: UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8B34E19C-EF53-416E-AE36-35C45BAFD2DE
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEngine.Networking.dll
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEditor;
namespace UnityEngine.Networking
{
/// <summary>
/// <para>This is the base class for type-specific SyncList classes.</para>
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class SyncList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
{
private List<T> m_Objects = new List<T>();
private NetworkBehaviour m_Behaviour;
private int m_CmdHash;
private SyncList<T>.SyncListChanged m_Callback;
public int Count
{
get
{
return this.m_Objects.Count;
}
}
public bool IsReadOnly
{
get
{
return false;
}
}
public SyncList<T>.SyncListChanged Callback
{
get
{
return this.m_Callback;
}
set
{
this.m_Callback = value;
}
}
public T this[int i]
{
get
{
return this.m_Objects[i];
}
set
{
bool flag = !this.m_Objects[i].Equals((object) value);
this.m_Objects[i] = value;
if (!flag)
return;
this.SendMsg(SyncList<T>.Operation.OP_SET, i, value);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator) this.GetEnumerator();
}
protected abstract void SerializeItem(NetworkWriter writer, T item);
protected abstract T DeserializeItem(NetworkReader reader);
public void InitializeBehaviour(NetworkBehaviour beh, int cmdHash)
{
this.m_Behaviour = beh;
this.m_CmdHash = cmdHash;
}
private void SendMsg(SyncList<T>.Operation op, int itemIndex, T item)
{
if ((Object) this.m_Behaviour == (Object) null)
{
if (!LogFilter.logError)
return;
Debug.LogError((object) "SyncList not initialized");
}
else
{
NetworkIdentity component = this.m_Behaviour.GetComponent<NetworkIdentity>();
if ((Object) component == (Object) null)
{
if (!LogFilter.logError)
return;
Debug.LogError((object) "SyncList no NetworkIdentity");
}
else
{
if (!component.isServer)
return;
NetworkWriter writer = new NetworkWriter();
writer.StartMessage((short) 9);
writer.Write(component.netId);
writer.WritePackedUInt32((uint) this.m_CmdHash);
writer.Write((byte) op);
writer.WritePackedUInt32((uint) itemIndex);
this.SerializeItem(writer, item);
writer.FinishMessage();
NetworkServer.SendWriterToReady(component.gameObject, writer, this.m_Behaviour.GetNetworkChannel());
NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, (short) 9, op.ToString(), 1);
if (!this.m_Behaviour.isServer || !this.m_Behaviour.isClient || this.m_Callback == null)
return;
this.m_Callback(op, itemIndex);
}
}
}
private void SendMsg(SyncList<T>.Operation op, int itemIndex)
{
this.SendMsg(op, itemIndex, default (T));
}
public void HandleMsg(NetworkReader reader)
{
byte num = reader.ReadByte();
int index = (int) reader.ReadPackedUInt32();
T obj = this.DeserializeItem(reader);
switch (num)
{
case 0:
this.m_Objects.Add(obj);
break;
case 1:
this.m_Objects.Clear();
break;
case 2:
this.m_Objects.Insert(index, obj);
break;
case 3:
this.m_Objects.Remove(obj);
break;
case 4:
this.m_Objects.RemoveAt(index);
break;
case 5:
case 6:
this.m_Objects[index] = obj;
break;
}
if (this.m_Callback == null)
return;
this.m_Callback((SyncList<T>.Operation) num, index);
}
internal void AddInternal(T item)
{
this.m_Objects.Add(item);
}
public void Add(T item)
{
this.m_Objects.Add(item);
this.SendMsg(SyncList<T>.Operation.OP_ADD, this.m_Objects.Count - 1, item);
}
public void Clear()
{
this.m_Objects.Clear();
this.SendMsg(SyncList<T>.Operation.OP_CLEAR, 0);
}
public bool Contains(T item)
{
return this.m_Objects.Contains(item);
}
public void CopyTo(T[] array, int index)
{
this.m_Objects.CopyTo(array, index);
}
public int IndexOf(T item)
{
return this.m_Objects.IndexOf(item);
}
public void Insert(int index, T item)
{
this.m_Objects.Insert(index, item);
this.SendMsg(SyncList<T>.Operation.OP_INSERT, index, item);
}
public bool Remove(T item)
{
bool flag = this.m_Objects.Remove(item);
if (flag)
this.SendMsg(SyncList<T>.Operation.OP_REMOVE, 0, item);
return flag;
}
public void RemoveAt(int index)
{
this.m_Objects.RemoveAt(index);
this.SendMsg(SyncList<T>.Operation.OP_REMOVEAT, index);
}
public void Dirty(int index)
{
this.SendMsg(SyncList<T>.Operation.OP_DIRTY, index, this.m_Objects[index]);
}
public IEnumerator<T> GetEnumerator()
{
return (IEnumerator<T>) this.m_Objects.GetEnumerator();
}
/// <summary>
/// <para>The types of operations that can occur for SyncLists.</para>
/// </summary>
public enum Operation
{
OP_ADD,
OP_CLEAR,
OP_INSERT,
OP_REMOVE,
OP_REMOVEAT,
OP_SET,
OP_DIRTY,
}
public delegate void SyncListChanged(SyncList<T>.Operation op, int itemIndex);
}
}