Skip to content

Commit 409f400

Browse files
committed
Merge branch 'develop' into sam/feature/client-network-transform
* develop: feat: INetworkMessage (#1187) fix: Increase timeout for UTP adapter tests (#1199) docs: Update repo and both package readme files (#1180) chore: updating UTP package to pull in DTLS fixes (#1197) fix: network time arguments (#1194) feat: network physics (#1175) # Conflicts: # com.unity.netcode.gameobjects/Components/Interpolator/BufferedLinearInterpolator.cs # com.unity.netcode.gameobjects/Components/NetworkTransform.cs # testproject/Assets/Prefabs/PlayerCube.prefab
2 parents bab085f + 6181e7e commit 409f400

File tree

239 files changed

+9985
-19597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+9985
-19597
lines changed

README.md

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,46 @@
1-
[![](https://i.imgur.com/d0amtqs.png)](https://mlapi.network/)
1+
[![Forums](https://img.shields.io/badge/unity--forums-multiplayer-blue)](https://forum.unity.com/forums/multiplayer.26/) [![Discord](https://img.shields.io/discord/449263083769036810.svg?label=discord&logo=discord&color=informational)](https://discord.gg/FM8SE9E)
2+
[![Website](https://img.shields.io/badge/docs-website-informational.svg)](https://docs-multiplayer.unity3d.com/) [![Api](https://img.shields.io/badge/docs-api-informational.svg)](https://docs-multiplayer.unity3d.com/docs/mlapi-api/introduction)
23

3-
[![GitHub Release](https://img.shields.io/github/release/MidLevel/MLAPI.svg?logo=github)](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/releases/latest)
4-
[![Github All Releases](https://img.shields.io/github/downloads/MidLevel/MLAPI/total.svg?logo=github&color=informational)](https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/releases)
4+
[![GitHub Release](https://img.shields.io/github/release/Unity-Technologies/com.unity.netcode.gameobjects.svg?logo=github)](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/releases/latest)
55

6-
[![Forums](https://img.shields.io/badge/unity--forums-multiplayer-blue)](https://forum.unity.com/forums/multiplayer.26/)
7-
[![Discord](https://img.shields.io/discord/449263083769036810.svg?label=discord&logo=discord&color=informational)](https://discord.gg/FM8SE9E)
6+
### Welcome!
87

8+
Welcome to the Netcode for GameObjects repository.
99

10-
[![Website](https://img.shields.io/badge/docs-website-informational.svg)](https://docs-multiplayer.unity3d.com/)
11-
[![Api](https://img.shields.io/badge/docs-api-informational.svg)](https://docs-multiplayer.unity3d.com/docs/mlapi-api/introduction)
12-
13-
14-
The Unity MLAPI (Mid level API) is a framework that simplifies building networked games in Unity. It offers **low level** access to core networking while at the same time providing **high level** abstractions. The MLAPI aims to remove the repetitive tasks and reduces the network code dramatically, no matter how many of the **modular** features you use.
10+
Netcode for GameObjects is a Unity package that provides networking capabilities to GameObject & MonoBehaviour workflows. The framework is interoperable with many low-level transports, including the official [Unity Transport Package](https://docs.unity3d.com/Packages/com.unity.transport@1.0/manual/index.html).
1511

1612
### Getting Started
17-
To get started, check the [Multiplayer Docs Site](https://docs-multiplayer.unity3d.com/).
13+
Visit the [Multiplayer Docs Site](https://docs-multiplayer.unity3d.com/) for package & API documentation, as well as information about several samples which leverage the Netcode for GameObjects package.
14+
15+
You can also jump right into our [Hello World](https://docs-multiplayer.unity3d.com/docs/tutorials/helloworld/helloworldintro/index.html) guide for a taste of how to use the framework for basic networked tasks.
1816

1917
### Community and Feedback
20-
For general questions, networking advice or discussions about MLAPI, please join our [Discord Community](https://discord.gg/FM8SE9E) or create a post in the [Unity Multiplayer Forum](https://forum.unity.com/forums/multiplayer.26/).
18+
For general questions, networking advice or discussions about Netcode for GameObjects, please join our [Discord Community](https://discord.gg/FM8SE9E) or create a post in the [Unity Multiplayer Forum](https://forum.unity.com/forums/multiplayer.26/).
2119

2220
### Compatibility
23-
The MLAPI supports all major Unity platforms. To use the WebGL platform a custom WebGL transport based on web sockets is needed.
2421

25-
MLAPI is compatible with Unity 2019 and newer versions.
22+
Netcode for GameObjects targets the following Unity versions:
23+
- Unity 2020.3, 2021.1, and 2021.2
24+
25+
On the following runtime platforms:
26+
- Windows, MacOS, and Linux
27+
- iOS and Android
28+
- Most closed platforms, such as consoles. Contact us for more information about specific closed platforms.
2629

2730
### Development
2831
We follow the [Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow). The master branch contains our latest stable release version while the develop branch tracks our current work.
2932

3033
This repository is broken into multiple components, each one implemented as a Unity Package.
3134
```
3235
.
33-
├── com.unity.multiplayer.mlapi # The core netcode SDK unity package (source + tests)
34-
├── com.unity.netcode.adapter.utp # Transport wrapper for com.unity.transport experimental package (not currently supported)
35-
└── testproject # A Unity project with various test implementations & scenes which exercise the features in the above package(s).
36+
├── com.unity.netcode.gameobjects # The core netcode SDK unity package (source + tests)
37+
├── com.unity.netcode.adapter.utp # Transport wrapper for com.unity.transport
38+
└── testproject # A Unity project with various test implementations & scenes which exercise the features in the above packages.
3639
```
3740

3841
### Contributing
39-
The MLAPI is an open-source project and we encourage and welcome
40-
contributions. If you wish to contribute, be sure to review our
41-
[contribution guidelines](CONTRIBUTING.md)
42+
We are an open-source project and we encourage and welcome contributions. If you wish to contribute, be sure to review our [contribution guidelines](CONTRIBUTING.md).
4243

43-
### Issues and missing features
44+
#### Issues and missing features
4445
If you have an issue, bug or feature request, please follow the information in our [contribution guidelines](CONTRIBUTING.md) to submit an issue.
45-
46-
### Example
47-
Here is a sample MonoBehaviour showing a chat script where everyone can write and read from. This shows the basis of the MLAPI and the abstractions it adds.
48-
49-
```csharp
50-
public class Chat : NetworkBehaviour
51-
{
52-
private NetworkList<string> ChatMessages = new NetworkList<string>(new MLAPI.NetworkVariable.NetworkVariableSettings()
53-
{
54-
ReadPermission = MLAPI.NetworkVariable.NetworkVariablePermission.Everyone,
55-
WritePermission = MLAPI.NetworkVariable.NetworkVariablePermission.Everyone,
56-
SendTickrate = 5
57-
}, new List<string>());
58-
59-
private string textField = "";
60-
61-
private void OnGUI()
62-
{
63-
if (IsClient)
64-
{
65-
textField = GUILayout.TextField(textField, GUILayout.Width(200));
66-
67-
if (GUILayout.Button("Send") && !string.IsNullOrWhiteSpace(textField))
68-
{
69-
ChatMessages.Add(textField);
70-
textField = "";
71-
}
72-
73-
for (int i = ChatMessages.Count - 1; i >= 0; i--)
74-
{
75-
GUILayout.Label(ChatMessages[i]);
76-
}
77-
}
78-
}
79-
}
80-
```
46+
You can also check out our public [roadmap](https://unity.com/roadmap/unity-platform/multiplayer-networking) to get an idea for what we might be working on next!
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
com.unity.transport transport for Netcode for GameObjects
1+
Unity Transport for Netcode for GameObjects is a transport adapter which enables the use of [Unity Transport Package](https://docs.unity3d.com/Packages/com.unity.transport@1.0/manual/index.html) as a low-level transport for Netcode for GameObjects.
22

3-
WIP: This is not a functional transport just a work in progress and should not be used as any measure of current state a very early proof of concept and place holder package.
3+
This library is an implementation of NetworkTransport to provide configuration and interoperability for Unity Transport with the Netcode for GameObjects package, enabling cross platform UDP-based network communication to a Unity project.

com.unity.netcode.adapter.utp/Tests/Runtime/Helpers/RuntimeTestsHelpers.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ namespace Unity.Netcode.UTP.RuntimeTests
99
{
1010
public static class RuntimeTestsHelpers
1111
{
12-
// 50ms should be plenty enough for any network interaction to occur (even roundtrips).
13-
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_ANDROID
14-
public const float MaxNetworkEventWaitTime = 0.35f;
15-
#else
16-
public const float MaxNetworkEventWaitTime = 0.15f;
17-
#endif
12+
// Half a second might seem like a very long time to wait for a network event, but in CI
13+
// many of the machines are underpowered (e.g. old Android devices or Macs) and there are
14+
// sometimes lag spikes that cause can cause delays upwards of 300ms.
15+
public const float MaxNetworkEventWaitTime = 0.5f;
1816

1917
// Wait for an event to appear in the given event list (must be the very next event).
2018
public static IEnumerator WaitForNetworkEvent(NetworkEvent type, List<TransportEvent> events)

com.unity.netcode.adapter.utp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"unity": "2020.3",
77
"dependencies": {
88
"com.unity.netcode.gameobjects": "0.0.1-preview.1",
9-
"com.unity.transport": "1.0.0-pre.4"
9+
"com.unity.transport": "1.0.0-pre.5"
1010
}
1111
}

com.unity.netcode.gameobjects/Components/Interpolator/BufferedLinearInterpolator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal interface IInterpolatorTime
1616
{
1717
double BufferedServerTime { get; }
1818
double BufferedServerFixedTime { get; }
19-
int TickRate { get; }
19+
uint TickRate { get; }
2020
}
2121

2222
private class InterpolatorTime : IInterpolatorTime
@@ -28,7 +28,7 @@ public InterpolatorTime(NetworkManager manager)
2828
}
2929
public double BufferedServerTime => m_Manager.ServerTime.Time;
3030
public double BufferedServerFixedTime => m_Manager.ServerTime.FixedTime;
31-
public int TickRate => m_Manager.ServerTime.TickRate;
31+
public uint TickRate => m_Manager.ServerTime.TickRate;
3232
}
3333

3434
internal IInterpolatorTime InterpolatorTimeProxy;

com.unity.netcode.gameobjects/Components/NetworkAnimator.cs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public bool SetTrigger(int key)
7676
return TriggerParameters.Add(key);
7777
}
7878

79-
public void NetworkSerialize(NetworkSerializer serializer)
79+
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
8080
{
8181
SerializeIntParameters(serializer);
8282
SerializeFloatParameters(serializer);
@@ -85,28 +85,28 @@ public void NetworkSerialize(NetworkSerializer serializer)
8585
SerializeAnimatorLayerStates(serializer);
8686
}
8787

88-
private void SerializeAnimatorLayerStates(NetworkSerializer serializer)
88+
private void SerializeAnimatorLayerStates<T>(BufferSerializer<T> serializer) where T : IReaderWriter
8989
{
90-
int layerCount = serializer.IsReading ? 0 : LayerStates.Length;
91-
serializer.Serialize(ref layerCount);
90+
int layerCount = serializer.IsReader ? 0 : LayerStates.Length;
91+
serializer.SerializeValue(ref layerCount);
9292

93-
if (serializer.IsReading && LayerStates.Length != layerCount)
93+
if (serializer.IsReader && LayerStates.Length != layerCount)
9494
{
9595
LayerStates = new LayerState[layerCount];
9696
}
9797

9898
for (int paramIndex = 0; paramIndex < layerCount; paramIndex++)
9999
{
100-
var stateHash = serializer.IsReading ? 0 : LayerStates[paramIndex].StateHash;
101-
serializer.Serialize(ref stateHash);
100+
var stateHash = serializer.IsReader ? 0 : LayerStates[paramIndex].StateHash;
101+
serializer.SerializeValue(ref stateHash);
102102

103-
var layerWeight = serializer.IsReading ? 0 : LayerStates[paramIndex].LayerWeight;
104-
serializer.Serialize(ref layerWeight);
103+
var layerWeight = serializer.IsReader ? 0 : LayerStates[paramIndex].LayerWeight;
104+
serializer.SerializeValue(ref layerWeight);
105105

106-
var normalizedStateTime = serializer.IsReading ? 0 : LayerStates[paramIndex].NormalizedStateTime;
107-
serializer.Serialize(ref normalizedStateTime);
106+
var normalizedStateTime = serializer.IsReader ? 0 : LayerStates[paramIndex].NormalizedStateTime;
107+
serializer.SerializeValue(ref normalizedStateTime);
108108

109-
if (serializer.IsReading)
109+
if (serializer.IsReader)
110110
{
111111
LayerStates[paramIndex] = new LayerState()
112112
{
@@ -118,103 +118,103 @@ private void SerializeAnimatorLayerStates(NetworkSerializer serializer)
118118
}
119119
}
120120

121-
private void SerializeTriggerParameters(NetworkSerializer serializer)
121+
private void SerializeTriggerParameters<T>(BufferSerializer<T> serializer) where T : IReaderWriter
122122
{
123-
int paramCount = serializer.IsReading ? 0 : TriggerParameters.Count;
124-
serializer.Serialize(ref paramCount);
123+
int paramCount = serializer.IsReader ? 0 : TriggerParameters.Count;
124+
serializer.SerializeValue(ref paramCount);
125125

126-
var paramArray = serializer.IsReading ? new int[paramCount] : TriggerParameters.ToArray();
126+
var paramArray = serializer.IsReader ? new int[paramCount] : TriggerParameters.ToArray();
127127
for (int i = 0; i < paramCount; i++)
128128
{
129-
var paramId = serializer.IsReading ? 0 : paramArray[i];
130-
serializer.Serialize(ref paramId);
129+
var paramId = serializer.IsReader ? 0 : paramArray[i];
130+
serializer.SerializeValue(ref paramId);
131131

132-
if (serializer.IsReading)
132+
if (serializer.IsReader)
133133
{
134134
paramArray[i] = paramId;
135135
}
136136
}
137137

138-
if (serializer.IsReading)
138+
if (serializer.IsReader)
139139
{
140140
TriggerParameters = new HashSet<int>(paramArray);
141141
}
142142
}
143143

144-
private void SerializeBoolParameters(NetworkSerializer serializer)
144+
private void SerializeBoolParameters<T>(BufferSerializer<T> serializer) where T : IReaderWriter
145145
{
146-
int paramCount = serializer.IsReading ? 0 : BoolParameters.Count;
147-
serializer.Serialize(ref paramCount);
146+
int paramCount = serializer.IsReader ? 0 : BoolParameters.Count;
147+
serializer.SerializeValue(ref paramCount);
148148

149-
var paramArray = serializer.IsReading ? new KeyValuePair<int, bool>[paramCount] : BoolParameters.ToArray();
149+
var paramArray = serializer.IsReader ? new KeyValuePair<int, bool>[paramCount] : BoolParameters.ToArray();
150150
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++)
151151
{
152-
var paramId = serializer.IsReading ? 0 : paramArray[paramIndex].Key;
153-
serializer.Serialize(ref paramId);
152+
var paramId = serializer.IsReader ? 0 : paramArray[paramIndex].Key;
153+
serializer.SerializeValue(ref paramId);
154154

155-
var paramBool = serializer.IsReading ? false : paramArray[paramIndex].Value;
156-
serializer.Serialize(ref paramBool);
155+
var paramBool = serializer.IsReader ? false : paramArray[paramIndex].Value;
156+
serializer.SerializeValue(ref paramBool);
157157

158-
if (serializer.IsReading)
158+
if (serializer.IsReader)
159159
{
160160
paramArray[paramIndex] = new KeyValuePair<int, bool>(paramId, paramBool);
161161
}
162162
}
163163

164-
if (serializer.IsReading)
164+
if (serializer.IsReader)
165165
{
166166
BoolParameters = paramArray.ToDictionary(pair => pair.Key, pair => pair.Value);
167167
}
168168
}
169169

170-
private void SerializeFloatParameters(NetworkSerializer serializer)
170+
private void SerializeFloatParameters<T>(BufferSerializer<T> serializer) where T : IReaderWriter
171171
{
172-
int paramCount = serializer.IsReading ? 0 : FloatParameters.Count;
173-
serializer.Serialize(ref paramCount);
172+
int paramCount = serializer.IsReader ? 0 : FloatParameters.Count;
173+
serializer.SerializeValue(ref paramCount);
174174

175-
var paramArray = serializer.IsReading ? new KeyValuePair<int, float>[paramCount] : FloatParameters.ToArray();
175+
var paramArray = serializer.IsReader ? new KeyValuePair<int, float>[paramCount] : FloatParameters.ToArray();
176176
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++)
177177
{
178-
var paramId = serializer.IsReading ? 0 : paramArray[paramIndex].Key;
179-
serializer.Serialize(ref paramId);
178+
var paramId = serializer.IsReader ? 0 : paramArray[paramIndex].Key;
179+
serializer.SerializeValue(ref paramId);
180180

181-
var paramFloat = serializer.IsReading ? 0 : paramArray[paramIndex].Value;
182-
serializer.Serialize(ref paramFloat);
181+
var paramFloat = serializer.IsReader ? 0 : paramArray[paramIndex].Value;
182+
serializer.SerializeValue(ref paramFloat);
183183

184-
if (serializer.IsReading)
184+
if (serializer.IsReader)
185185
{
186186
paramArray[paramIndex] = new KeyValuePair<int, float>(paramId, paramFloat);
187187
}
188188
}
189189

190-
if (serializer.IsReading)
190+
if (serializer.IsReader)
191191
{
192192
FloatParameters = paramArray.ToDictionary(pair => pair.Key, pair => pair.Value);
193193
}
194194
}
195195

196-
private void SerializeIntParameters(NetworkSerializer serializer)
196+
private void SerializeIntParameters<T>(BufferSerializer<T> serializer) where T : IReaderWriter
197197
{
198-
int paramCount = serializer.IsReading ? 0 : IntParameters.Count;
199-
serializer.Serialize(ref paramCount);
198+
int paramCount = serializer.IsReader ? 0 : IntParameters.Count;
199+
serializer.SerializeValue(ref paramCount);
200200

201-
var paramArray = serializer.IsReading ? new KeyValuePair<int, int>[paramCount] : IntParameters.ToArray();
201+
var paramArray = serializer.IsReader ? new KeyValuePair<int, int>[paramCount] : IntParameters.ToArray();
202202

203203
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++)
204204
{
205-
var paramId = serializer.IsReading ? 0 : paramArray[paramIndex].Key;
206-
serializer.Serialize(ref paramId);
205+
var paramId = serializer.IsReader ? 0 : paramArray[paramIndex].Key;
206+
serializer.SerializeValue(ref paramId);
207207

208-
var paramInt = serializer.IsReading ? 0 : paramArray[paramIndex].Value;
209-
serializer.Serialize(ref paramInt);
208+
var paramInt = serializer.IsReader ? 0 : paramArray[paramIndex].Value;
209+
serializer.SerializeValue(ref paramInt);
210210

211-
if (serializer.IsReading)
211+
if (serializer.IsReader)
212212
{
213213
paramArray[paramIndex] = new KeyValuePair<int, int>(paramId, paramInt);
214214
}
215215
}
216216

217-
if (serializer.IsReading)
217+
if (serializer.IsReader)
218218
{
219219
IntParameters = paramArray.ToDictionary(pair => pair.Key, pair => pair.Value);
220220
}

0 commit comments

Comments
 (0)