Skip to content

Commit fe88778

Browse files
committed
Removed networkedBehaviourId
1 parent 0d47c69 commit fe88778

File tree

5 files changed

+34
-70
lines changed

5 files changed

+34
-70
lines changed

MLAPI/MLAPI.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -73,7 +73,6 @@
7373
<Compile Include="NetworkingManagerComponents\NetworkPoolManager.cs" />
7474
<Compile Include="NetworkingManagerComponents\NetworkSceneManager.cs" />
7575
<Compile Include="NetworkingManagerComponents\SpawnManager.cs" />
76-
<Compile Include="NetworkingManagerComponents\SyncedVarManager.cs" />
7776
<Compile Include="Properties\AssemblyInfo.cs" />
7877
</ItemGroup>
7978
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ private void OnDestroy()
134134
private List<object> syncedFieldValues = new List<object>();
135135
//A dirty field is a field that's not synced.
136136
public bool[] dirtyFields;
137-
protected static ushort networkedBehaviourId;
138-
//This is just for the unity editor. if you turn the editor to DEBUG mode you can see what the networkedBehaviourId is.
139-
private ushort _networkedBehaviourId = networkedBehaviourId;
140137
internal void SyncVarInit()
141138
{
142139
FieldInfo[] sortedFields = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance).OrderBy(x => x.Name).ToArray();
@@ -274,7 +271,6 @@ internal void FlushToClient(int clientId)
274271
{
275272
writer.Write(networkId);
276273
writer.Write(networkedObject.GetOrderIndex(this));
277-
writer.Write(networkedBehaviourId);
278274
writer.Write(i); //Index
279275
switch (syncedFieldTypes[i])
280276
{
@@ -364,7 +360,6 @@ internal void SyncVarUpdate()
364360
{
365361
writer.Write(networkId);
366362
writer.Write(networkedObject.GetOrderIndex(this));
367-
writer.Write(networkedBehaviourId);
368363
writer.Write(i); //Index
369364
switch (syncedFieldTypes[i])
370365
{

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,45 +64,53 @@ public void ChangeOwnership(int newOwnerClientId)
6464

6565
internal void InvokeBehaviourOnLostOwnership()
6666
{
67-
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
68-
for (int i = 0; i < netBehaviours.Length; i++)
67+
for (int i = 0; i < childNetworkedBehaviours.Count; i++)
6968
{
70-
//We check if we are it's networkedObject owner incase a networkedObject exists as a child of our networkedObject.
71-
if (netBehaviours[i].networkedObject == this)
72-
{
73-
netBehaviours[i].OnLostOwnership();
74-
}
69+
childNetworkedBehaviours[i].OnLostOwnership();
7570
}
7671
}
7772

7873
internal void InvokeBehaviourOnGainedOwnership()
7974
{
80-
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
81-
for (int i = 0; i < netBehaviours.Length; i++)
75+
for (int i = 0; i < childNetworkedBehaviours.Count; i++)
8276
{
83-
//We check if we are it's networkedObject owner incase a networkedObject exists as a child of our networkedObject.
84-
if (netBehaviours[i].networkedObject == this)
85-
{
86-
netBehaviours[i].OnGainedOwnership();
87-
}
77+
childNetworkedBehaviours[i].OnGainedOwnership();
8878
}
8979
}
9080

9181
internal void InvokeBehaviourNetworkSpawn()
9282
{
93-
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
94-
for (int i = 0; i < netBehaviours.Length; i++)
83+
for (int i = 0; i < childNetworkedBehaviours.Count; i++)
9584
{
9685
//We check if we are it's networkedObject owner incase a networkedObject exists as a child of our networkedObject.
97-
if(netBehaviours[i].networkedObject == this && !netBehaviours[i].networkedStartInvoked)
86+
if(!childNetworkedBehaviours[i].networkedStartInvoked)
9887
{
99-
netBehaviours[i].NetworkStart();
88+
childNetworkedBehaviours[i].NetworkStart();
10089
if (NetworkingManager.singleton.isServer)
101-
netBehaviours[i].SyncVarInit();
90+
childNetworkedBehaviours[i].SyncVarInit();
10291
}
10392
}
10493
}
10594

95+
private List<NetworkedBehaviour> _childNetworkedBehaviours;
96+
internal List<NetworkedBehaviour> childNetworkedBehaviours
97+
{
98+
get
99+
{
100+
if(_childNetworkedBehaviours == null)
101+
{
102+
_childNetworkedBehaviours = new List<NetworkedBehaviour>();
103+
NetworkedBehaviour[] behaviours = GetComponentsInChildren<NetworkedBehaviour>();
104+
for (int i = 0; i < behaviours.Length; i++)
105+
{
106+
if (behaviours[i].networkedObject == this)
107+
_childNetworkedBehaviours.Add(behaviours[i]);
108+
}
109+
}
110+
return _childNetworkedBehaviours;
111+
}
112+
}
113+
106114
internal static List<NetworkedBehaviour> NetworkedBehaviours = new List<NetworkedBehaviour>();
107115
internal static void InvokeSyncvarUpdate()
108116
{
@@ -115,27 +123,26 @@ internal static void InvokeSyncvarUpdate()
115123
//Flushes all syncVars to client
116124
internal void FlushToClient(int clientId)
117125
{
118-
for (int i = 0; i < NetworkedBehaviours.Count; i++)
126+
for (int i = 0; i < childNetworkedBehaviours.Count; i++)
119127
{
120-
NetworkedBehaviours[i].FlushToClient(clientId);
128+
childNetworkedBehaviours[i].FlushToClient(clientId);
121129
}
122130
}
123131

124132
internal ushort GetOrderIndex(NetworkedBehaviour instance)
125133
{
126-
NetworkedBehaviour[] behaviours = GetComponentsInChildren<NetworkedBehaviour>();
127-
for (ushort i = 0; i < behaviours.Length; i++)
134+
for (ushort i = 0; i < childNetworkedBehaviours.Count; i++)
128135
{
129-
if (behaviours[i].networkedObject == this && behaviours[i] == instance)
136+
if (childNetworkedBehaviours[i] == instance)
130137
return i;
131138
}
132139
return 0;
133140
}
134141

135142
internal NetworkedBehaviour GetBehaviourAtOrderIndex(ushort index)
136143
{
137-
NetworkedBehaviour[] behaviours = GetComponentsInChildren<NetworkedBehaviour>();
138-
return behaviours[index];
144+
//TODO index out of bounds
145+
return childNetworkedBehaviours[index];
139146
}
140147
}
141148
}

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ private ConnectionConfig Init(NetworkingConfiguration netConfig)
7474
{
7575
NetworkConfig = netConfig;
7676

77-
SyncedVarManager.Init();
7877
pendingClients = new HashSet<int>();
7978
connectedClients = new Dictionary<int, NetworkedClient>();
8079
messageBuffer = new byte[NetworkConfig.MessageBufferSize];
@@ -697,7 +696,6 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
697696
{
698697
uint netId = messageReader.ReadUInt32(); //NetId the syncvar is from
699698
ushort orderIndex = messageReader.ReadUInt16();
700-
ushort networkBehaviourId = messageReader.ReadUInt16();
701699
byte fieldIndex = messageReader.ReadByte();
702700
FieldType type = SpawnManager.spawnedObjects[netId].GetBehaviourAtOrderIndex(orderIndex).syncedFieldTypes[fieldIndex];
703701
switch (type)

MLAPI/NetworkingManagerComponents/SyncedVarManager.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)