Skip to content

Commit bfe9e9b

Browse files
committed
Added NetworkedAnimator & fixed zPos sync on NetworkedTransform
1 parent 27ae0bc commit bfe9e9b

File tree

5 files changed

+360
-12
lines changed

5 files changed

+360
-12
lines changed

MLAPI/MLAPI.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<PlatformTarget>AnyCPU</PlatformTarget>
4242
<ErrorReport>prompt</ErrorReport>
4343
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
44+
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
4445
</PropertyGroup>
4546
<ItemGroup>
4647
<Reference Include="System" />
@@ -57,6 +58,7 @@
5758
<ItemGroup>
5859
<Compile Include="Data\NetworkPool.cs" />
5960
<Compile Include="Data\TrackedPointData.cs" />
61+
<Compile Include="MonoBehaviours\Prototyping\NetworkedAnimator.cs" />
6062
<Compile Include="NetworkingManagerComponents\LagCompensationManager.cs" />
6163
<Compile Include="MonoBehaviours\Core\NetworkedBehaviour.cs" />
6264
<Compile Include="Data\NetworkedClient.cs" />

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected void SendToLocalClientTarget(string messageType, string channelName, b
164164
NetworkingManager.singleton.Send(ownerClientId, messageType, channelName, data, networkId);
165165
}
166166

167-
protected void SendToNonLocalClients(string messageType, string channelName, byte[] data)
167+
protected void SendToNonLocalClients(string messageType, string channelName, byte[] data, bool ignoreHost = false)
168168
{
169169
if (MessageManager.messageTypes[messageType] < 32)
170170
{
@@ -176,10 +176,10 @@ protected void SendToNonLocalClients(string messageType, string channelName, byt
176176
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
177177
return;
178178
}
179-
NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId);
179+
NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId, null, ignoreHost);
180180
}
181181

182-
protected void SendToNonLocalClientsTarget(string messageType, string channelName, byte[] data)
182+
protected void SendToNonLocalClientsTarget(string messageType, string channelName, byte[] data, bool ignoreHost = false)
183183
{
184184
if (MessageManager.messageTypes[messageType] < 32)
185185
{
@@ -191,7 +191,7 @@ protected void SendToNonLocalClientsTarget(string messageType, string channelNam
191191
Debug.LogWarning("MLAPI: Sending messages from client to other clients is not yet supported");
192192
return;
193193
}
194-
NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId, networkId);
194+
NetworkingManager.singleton.Send(messageType, channelName, data, ownerClientId, networkId, true);
195195
}
196196

197197
protected void SendToClient(int clientId, string messageType, string channelName, byte[] data)

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private ConnectionConfig Init(NetworkingConfiguration netConfig)
9393
//MLAPI channels and messageTypes
9494
NetworkConfig.Channels.Add("MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", QosType.ReliableFragmentedSequenced);
9595
NetworkConfig.Channels.Add("MLAPI_POSITION_UPDATE", QosType.StateUpdate);
96+
NetworkConfig.Channels.Add("MLAPI_ANIMATION_UPDATE", QosType.ReliableSequenced);
9697
MessageManager.messageTypes.Add("MLAPI_CONNECTION_REQUEST", 0);
9798
MessageManager.messageTypes.Add("MLAPI_CONNECTION_APPROVED", 1);
9899
MessageManager.messageTypes.Add("MLAPI_ADD_OBJECT", 2);
@@ -104,14 +105,21 @@ private ConnectionConfig Init(NetworkingConfiguration netConfig)
104105
MessageManager.messageTypes.Add("MLAPI_CHANGE_OWNER", 8);
105106
NetworkConfig.MessageTypes.Add("MLAPI_OnRecieveTransformFromClient");
106107
NetworkConfig.MessageTypes.Add("MLAPI_OnRecieveTransformFromServer");
108+
NetworkConfig.MessageTypes.Add("MLAPI_HandleAnimationMessage");
109+
NetworkConfig.MessageTypes.Add("MLAPI_HandleAnimationParameterMessage");
110+
NetworkConfig.MessageTypes.Add("MLAPI_HandleAnimationTriggerMessage");
107111

108-
for (int i = 0; i < NetworkConfig.RegisteredScenes.Count; i++)
112+
if (NetworkConfig.EnableSceneSwitching)
109113
{
110-
NetworkSceneManager.registeredSceneNames.Add(NetworkConfig.RegisteredScenes[i]);
111-
NetworkSceneManager.sceneIndexToString.Add((uint)i, NetworkConfig.RegisteredScenes[i]);
112-
NetworkSceneManager.sceneNameToIndex.Add(NetworkConfig.RegisteredScenes[i], (uint)i);
114+
for (int i = 0; i < NetworkConfig.RegisteredScenes.Count; i++)
115+
{
116+
NetworkSceneManager.registeredSceneNames.Add(NetworkConfig.RegisteredScenes[i]);
117+
NetworkSceneManager.sceneIndexToString.Add((uint)i, NetworkConfig.RegisteredScenes[i]);
118+
NetworkSceneManager.sceneNameToIndex.Add(NetworkConfig.RegisteredScenes[i], (uint)i);
119+
}
120+
121+
NetworkSceneManager.SetCurrentSceneIndex();
113122
}
114-
NetworkSceneManager.SetCurrentSceneIndex();
115123

116124

117125
HashSet<string> channelNames = new HashSet<string>();
@@ -859,7 +867,7 @@ internal void Send(string messageType, string channelName, byte[] data, uint? ne
859867
}
860868
}
861869

862-
internal void Send(string messageType, string channelName, byte[] data, int clientIdToIgnore, uint? networkId = null)
870+
internal void Send(string messageType, string channelName, byte[] data, int clientIdToIgnore, uint? networkId = null, bool ignoreHost = false)
863871
{
864872
//2 bytes for messageType, 2 bytes for buffer length and one byte for target bool
865873
int sizeOfStream = 5;
@@ -885,7 +893,7 @@ internal void Send(string messageType, string channelName, byte[] data, int clie
885893
if (pair.Key == clientIdToIgnore)
886894
continue;
887895
int clientId = pair.Key;
888-
if (isHost && pair.Key == -1)
896+
if (isHost && pair.Key == -1 && !ignoreHost)
889897
{
890898
if (networkId == null)
891899
MessageManager.InvokeMessageHandlers(messageType, data, clientId);

0 commit comments

Comments
 (0)