Skip to content

Commit e7dbd60

Browse files
committed
Moving ClientNetworkTransform to the Utilities package
Cleaning up the Utilities package
1 parent 4c6ae1b commit e7dbd60

File tree

7 files changed

+100
-16
lines changed

7 files changed

+100
-16
lines changed

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/ClientAuthority.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "ClientAuthority",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:3b8ed52f1b5c64994af4c4e0aa4b6c4b",
6+
"GUID:1491147abca9d7d4bb7105af628b223e"
7+
],
8+
"includePlatforms": [],
9+
"excludePlatforms": [],
10+
"allowUnsafeCode": false,
11+
"overrideReferences": false,
12+
"precompiledReferences": [],
13+
"autoReferenced": true,
14+
"defineConstraints": [],
15+
"versionDefines": [],
16+
"noEngineReferences": false
17+
}

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/ClientAuthority/ClientAuthority.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Unity.Netcode.Components;
2+
using UnityEngine;
3+
4+
namespace Unity.Netcode.Samples
5+
{
6+
// TODO change to owner netvar instead of RPC based
7+
/// <summary>
8+
/// Used for syncing a transform with client side changes. This includes host. Pure server as owner isn't supported by this. Please use NetworkTransform
9+
/// for transforms that'll always be owned by the server.
10+
/// </summary>
11+
[DisallowMultipleComponent]
12+
public class ClientNetworkTransform : NetworkTransform
13+
{
14+
/// <summary>
15+
/// Used to determine who can write to this transform. Owner client only.
16+
/// Changing this value alone will not allow you to create a NetworkTransform which can be written to by clients.
17+
/// We're using RPCs to send updated values from client to server. Netcode doesn't support client side network variable writing.
18+
/// This imposes state to the server. This is putting trust on your clients. Make sure no security-sensitive features use this transform.
19+
/// </summary>
20+
// This is public to make sure that users don't depend on this IsClient && IsOwner check in their code. If this logic changes in the future, we can make it invisible here
21+
22+
public override void OnNetworkSpawn()
23+
{
24+
base.OnNetworkSpawn();
25+
CanCommitToTransform = IsOwner;
26+
}
27+
28+
protected override void Update()
29+
{
30+
CanCommitToTransform = IsOwner;
31+
base.Update();
32+
if (NetworkManager.Singleton != null && (NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsListening))
33+
{
34+
if (CanCommitToTransform)
35+
{
36+
TryCommitTransformToServer(transform, NetworkManager.LocalTime.Time);
37+
}
38+
}
39+
}
40+
}
41+
}

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/ClientAuthority/ClientNetworkTransform.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.multiplayer.samples.coop/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "com.unity.multiplayer.samples.coop",
3-
"displayName": "Boss Room",
4-
"version": "1.1.0-pre",
2+
"name": "com.unity.com.unity.multiplayer.samples.utilities",
3+
"displayName": "Samples Utilities",
4+
"version": "1.2.0-pre",
55
"type": "template",
66
"host": "hub",
77
"unity": "2020.3",
8-
"description": "Boss Room is a small scale cooperative game sample project built on top of the new Unity Networking Core library, designed to help you explore the concepts and patterns behind a multiplayer game flow. \n\nBoss Room features character abilities, casting animations to hide latency, replicated objects, RPCs, and integration with a relay service.",
8+
"description": "Utilities package built on top of Netcode for GameObjects, providing useful scripts and tools.",
99
"dependencies": {
1010
"com.unity.learn.iet-framework": "1.2.1",
1111
"com.unity.netcode.gameobjects": "1.0.0-pre.7",

Packages/packages-lock.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@
5050
},
5151
"url": "https://packages.unity.com"
5252
},
53+
"com.unity.com.unity.multiplayer.samples.utilities": {
54+
"version": "file:com.unity.multiplayer.samples.coop",
55+
"depth": 0,
56+
"source": "embedded",
57+
"dependencies": {
58+
"com.unity.learn.iet-framework": "1.2.1",
59+
"com.unity.netcode.gameobjects": "1.0.0-pre.7",
60+
"com.unity.services.authentication": "1.0.0-pre.4",
61+
"com.unity.services.lobby": "1.0.0-pre.6",
62+
"com.unity.services.relay": "1.0.1-pre.5"
63+
}
64+
},
5365
"com.unity.editorcoroutines": {
5466
"version": "1.0.0",
5567
"depth": 1,
@@ -115,18 +127,6 @@
115127
},
116128
"url": "https://packages.unity.com"
117129
},
118-
"com.unity.multiplayer.samples.coop": {
119-
"version": "file:com.unity.multiplayer.samples.coop",
120-
"depth": 0,
121-
"source": "embedded",
122-
"dependencies": {
123-
"com.unity.learn.iet-framework": "1.2.1",
124-
"com.unity.netcode.gameobjects": "1.0.0-pre.7",
125-
"com.unity.services.authentication": "1.0.0-pre.4",
126-
"com.unity.services.lobby": "1.0.0-pre.6",
127-
"com.unity.services.relay": "1.0.1-pre.5"
128-
}
129-
},
130130
"com.unity.multiplayer.tools": {
131131
"version": "1.0.0-pre.6",
132132
"depth": 0,

0 commit comments

Comments
 (0)