mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
NT Unreliable version
This commit is contained in:
parent
801aca4889
commit
630ae86a65
@ -298,7 +298,7 @@ protected virtual void OnClientToServerSync(Vector3? position, Quaternion? rotat
|
|||||||
// Debug.Log($"{name}: corrected history on server to fix initial stutter after not sending for a while.");
|
// Debug.Log($"{name}: corrected history on server to fix initial stutter after not sending for a while.");
|
||||||
}
|
}
|
||||||
|
|
||||||
AddSnapshot(serverSnapshots, connectionToClient.remoteTimeStamp, position, rotation, scale);
|
AddSnapshot(serverSnapshots, connectionToClient.remoteTimeStamp + NetworkServer.sendInterval, position, rotation, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// server broadcasts sync message to all clients
|
// server broadcasts sync message to all clients
|
||||||
@ -322,7 +322,7 @@ protected virtual void OnServerToClientSync(Vector3? position, Quaternion? rotat
|
|||||||
// Debug.Log($"{name}: corrected history on client to fix initial stutter after not sending for a while.");
|
// Debug.Log($"{name}: corrected history on client to fix initial stutter after not sending for a while.");
|
||||||
}
|
}
|
||||||
|
|
||||||
AddSnapshot(clientSnapshots, NetworkClient.connection.remoteTimeStamp, position, rotation, scale);
|
AddSnapshot(clientSnapshots, NetworkClient.connection.remoteTimeStamp + NetworkClient.sendInterval, position, rotation, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only sync on change /////////////////////////////////////////////////
|
// only sync on change /////////////////////////////////////////////////
|
||||||
|
1261
Assets/Mirror/Examples/TestNT/Prefabs/Bot-U.prefab
Normal file
1261
Assets/Mirror/Examples/TestNT/Prefabs/Bot-U.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Mirror/Examples/TestNT/Prefabs/Bot-U.prefab.meta
Normal file
7
Assets/Mirror/Examples/TestNT/Prefabs/Bot-U.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: daa43d6577eba4240807391d6c63ea8d
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -12,7 +12,7 @@ GameObject:
|
|||||||
- component: {fileID: 365631096971600796}
|
- component: {fileID: 365631096971600796}
|
||||||
- component: {fileID: 8879100155897503324}
|
- component: {fileID: 8879100155897503324}
|
||||||
- component: {fileID: 3417360630707946970}
|
- component: {fileID: 3417360630707946970}
|
||||||
- component: {fileID: 8096906436974498748}
|
- component: {fileID: -3326358089088084113}
|
||||||
- component: {fileID: 6545184674585495222}
|
- component: {fileID: 6545184674585495222}
|
||||||
- component: {fileID: 4832621091644330542}
|
- component: {fileID: 4832621091644330542}
|
||||||
- component: {fileID: 7961362217038480789}
|
- component: {fileID: 7961362217038480789}
|
||||||
@ -91,7 +91,7 @@ MonoBehaviour:
|
|||||||
serverOnly: 0
|
serverOnly: 0
|
||||||
visible: 0
|
visible: 0
|
||||||
hasSpawned: 0
|
hasSpawned: 0
|
||||||
--- !u!114 &8096906436974498748
|
--- !u!114 &-3326358089088084113
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
@ -100,10 +100,10 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 629047657802428152}
|
m_GameObject: {fileID: 629047657802428152}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 58d4ed8e905e2f0419873bf2d4a973b8, type: 3}
|
m_Script: {fileID: 11500000, guid: 8ff3ba0becae47b8b9381191598957c8, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
syncDirection: 1
|
syncDirection: 0
|
||||||
syncMode: 0
|
syncMode: 0
|
||||||
syncInterval: 0
|
syncInterval: 0
|
||||||
target: {fileID: 3821606276970024013}
|
target: {fileID: 3821606276970024013}
|
||||||
@ -120,11 +120,9 @@ MonoBehaviour:
|
|||||||
onlySyncOnChange: 1
|
onlySyncOnChange: 1
|
||||||
onlySyncOnChangeCorrectionMultiplier: 2
|
onlySyncOnChangeCorrectionMultiplier: 2
|
||||||
rotationSensitivity: 0.02
|
rotationSensitivity: 0.02
|
||||||
compressRotation: 1
|
compressRotation: 0
|
||||||
positionPrecision: 0.02
|
positionPrecision: 0.02
|
||||||
scalePrecision: 0.02
|
scalePrecision: 0.02
|
||||||
velocity: {x: 0, y: 0, z: 0}
|
|
||||||
angVelocity: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!114 &6545184674585495222
|
--- !u!114 &6545184674585495222
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -193,7 +191,7 @@ MonoBehaviour:
|
|||||||
syncMode: 0
|
syncMode: 0
|
||||||
syncInterval: 0.1
|
syncInterval: 0.1
|
||||||
NTRCustomSendInterval: {fileID: 0}
|
NTRCustomSendInterval: {fileID: 0}
|
||||||
NetworkTransformReliable: {fileID: 8096906436974498748}
|
NetworkTransformReliable: {fileID: -3326358089088084113}
|
||||||
serverBufferText: {fileID: 2520575634317220638}
|
serverBufferText: {fileID: 2520575634317220638}
|
||||||
clientBufferText: {fileID: 9167280228736349983}
|
clientBufferText: {fileID: 9167280228736349983}
|
||||||
snapIntText: {fileID: 1649625818729847816}
|
snapIntText: {fileID: 1649625818729847816}
|
||||||
|
@ -1075,7 +1075,7 @@ GameObject:
|
|||||||
- component: {fileID: 8094616116228944553}
|
- component: {fileID: 8094616116228944553}
|
||||||
- component: {fileID: 1044772989000519529}
|
- component: {fileID: 1044772989000519529}
|
||||||
- component: {fileID: 6497505213013742831}
|
- component: {fileID: 6497505213013742831}
|
||||||
- component: {fileID: 367848704157024905}
|
- component: {fileID: 1251736242665180418}
|
||||||
- component: {fileID: 3427814615500822403}
|
- component: {fileID: 3427814615500822403}
|
||||||
- component: {fileID: 3915821277891986203}
|
- component: {fileID: 3915821277891986203}
|
||||||
- component: {fileID: -2480596454832827664}
|
- component: {fileID: -2480596454832827664}
|
||||||
@ -1154,7 +1154,7 @@ MonoBehaviour:
|
|||||||
serverOnly: 0
|
serverOnly: 0
|
||||||
visible: 0
|
visible: 0
|
||||||
hasSpawned: 0
|
hasSpawned: 0
|
||||||
--- !u!114 &367848704157024905
|
--- !u!114 &1251736242665180418
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
@ -1163,7 +1163,7 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 9078678990242496461}
|
m_GameObject: {fileID: 9078678990242496461}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 58d4ed8e905e2f0419873bf2d4a973b8, type: 3}
|
m_Script: {fileID: 11500000, guid: 2f74aedd71d9a4f55b3ce499326d45fb, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
syncDirection: 0
|
syncDirection: 0
|
||||||
@ -1181,13 +1181,10 @@ MonoBehaviour:
|
|||||||
showOverlay: 0
|
showOverlay: 0
|
||||||
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
|
||||||
onlySyncOnChange: 1
|
onlySyncOnChange: 1
|
||||||
onlySyncOnChangeCorrectionMultiplier: 2
|
bufferResetMultiplier: 5
|
||||||
|
positionSensitivity: 0.02
|
||||||
rotationSensitivity: 0.02
|
rotationSensitivity: 0.02
|
||||||
compressRotation: 1
|
scaleSensitivity: 0.02
|
||||||
positionPrecision: 0.02
|
|
||||||
scalePrecision: 0.02
|
|
||||||
velocity: {x: 0, y: 0, z: 0}
|
|
||||||
angVelocity: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!114 &3427814615500822403
|
--- !u!114 &3427814615500822403
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -1256,7 +1253,7 @@ MonoBehaviour:
|
|||||||
syncMode: 0
|
syncMode: 0
|
||||||
syncInterval: 0.1
|
syncInterval: 0.1
|
||||||
NTRCustomSendInterval: {fileID: 0}
|
NTRCustomSendInterval: {fileID: 0}
|
||||||
NetworkTransformReliable: {fileID: 367848704157024905}
|
NetworkTransformReliable: {fileID: 0}
|
||||||
serverBufferText: {fileID: 6322424803937864235}
|
serverBufferText: {fileID: 6322424803937864235}
|
||||||
clientBufferText: {fileID: 756491762232780330}
|
clientBufferText: {fileID: 756491762232780330}
|
||||||
snapIntText: {fileID: 7179727379187289405}
|
snapIntText: {fileID: 7179727379187289405}
|
||||||
|
@ -234,7 +234,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 0110f245bfcfc7d459681f7bd9ebc590, type: 3}
|
m_Script: {fileID: 11500000, guid: 0110f245bfcfc7d459681f7bd9ebc590, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
port: 7777
|
port: 7778
|
||||||
maxMessageSize: 16384
|
maxMessageSize: 16384
|
||||||
handshakeMaxSize: 3000
|
handshakeMaxSize: 3000
|
||||||
noDelay: 1
|
noDelay: 1
|
||||||
@ -288,7 +288,7 @@ MonoBehaviour:
|
|||||||
deliveryTimeEmaDuration: 2
|
deliveryTimeEmaDuration: 2
|
||||||
timeInterpolationGui: 1
|
timeInterpolationGui: 1
|
||||||
playerNinjaPrefab: {fileID: 1428992836745641328, guid: 4b4e4d1a8090c7a45bab0cbc52ccfd76, type: 3}
|
playerNinjaPrefab: {fileID: 1428992836745641328, guid: 4b4e4d1a8090c7a45bab0cbc52ccfd76, type: 3}
|
||||||
botPrefab: {fileID: 629047657802428152, guid: 45e99b6415bfdc846bbbfc2d949d53f5, type: 3}
|
botPrefab: {fileID: 297236141164807331, guid: daa43d6577eba4240807391d6c63ea8d, type: 3}
|
||||||
npcPrefab: {fileID: 9078678990242496461, guid: 41855c7cf63a3dc45ac8a93b4e2ecd54, type: 3}
|
npcPrefab: {fileID: 9078678990242496461, guid: 41855c7cf63a3dc45ac8a93b4e2ecd54, type: 3}
|
||||||
botNinjaPrefab: {fileID: 2972877558187846166, guid: 186c06a2be59cc84db82de14fccac374, type: 3}
|
botNinjaPrefab: {fileID: 2972877558187846166, guid: 186c06a2be59cc84db82de14fccac374, type: 3}
|
||||||
npcNinjaPrefab: {fileID: 388172571495221481, guid: 4f67582aaba8f814cae98c38f4e9782d, type: 3}
|
npcNinjaPrefab: {fileID: 388172571495221481, guid: 4f67582aaba8f814cae98c38f4e9782d, type: 3}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Mirror;
|
using Mirror;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace TestNT
|
namespace TestNT
|
||||||
{
|
{
|
||||||
@ -9,57 +9,9 @@ public class NTReliableExt : NetworkTransformReliable
|
|||||||
public Action<Vector3, Vector3> VelRotChangedAction;
|
public Action<Vector3, Vector3> VelRotChangedAction;
|
||||||
|
|
||||||
[Header("Snapshot Interpolation")]
|
[Header("Snapshot Interpolation")]
|
||||||
//public double t;
|
|
||||||
//public int fromIndex;
|
|
||||||
//public int toIndex;
|
|
||||||
public Vector3 velocity;
|
public Vector3 velocity;
|
||||||
public Vector3 angVelocity;
|
public Vector3 angVelocity;
|
||||||
|
|
||||||
#region Unity Callbacks
|
|
||||||
|
|
||||||
protected override void OnValidate()
|
|
||||||
{
|
|
||||||
base.OnValidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Awake()
|
|
||||||
{
|
|
||||||
base.Awake();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnEnable()
|
|
||||||
{
|
|
||||||
base.OnEnable();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDisable()
|
|
||||||
{
|
|
||||||
base.OnDisable();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region NetworkTransformBase Methods
|
|
||||||
|
|
||||||
protected override bool Changed(TransformSnapshot current)
|
|
||||||
{
|
|
||||||
return base.Changed(current);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnServerToClientSync(Vector3? position, Quaternion? rotation, Vector3? scale)
|
|
||||||
{
|
|
||||||
base.OnServerToClientSync(position, rotation, scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnClientToServerSync(Vector3? position, Quaternion? rotation, Vector3? scale)
|
|
||||||
{
|
|
||||||
base.OnClientToServerSync(position, rotation, scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region NetworkTransformReliable Methods
|
|
||||||
|
|
||||||
protected override void Apply(TransformSnapshot interpolated, TransformSnapshot endGoal)
|
protected override void Apply(TransformSnapshot interpolated, TransformSnapshot endGoal)
|
||||||
{
|
{
|
||||||
base.Apply(interpolated, endGoal);
|
base.Apply(interpolated, endGoal);
|
||||||
@ -71,17 +23,5 @@ protected override void Apply(TransformSnapshot interpolated, TransformSnapshot
|
|||||||
VelRotChangedAction?.Invoke(velocity, angVelocity);
|
VelRotChangedAction?.Invoke(velocity, angVelocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override TransformSnapshot Construct()
|
|
||||||
{
|
|
||||||
return base.Construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Reset()
|
|
||||||
{
|
|
||||||
base.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
Assets/Mirror/Examples/TestNT/Scripts/NTUnreliableExt.cs
Normal file
24
Assets/Mirror/Examples/TestNT/Scripts/NTUnreliableExt.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using Mirror;
|
||||||
|
|
||||||
|
public class NTUnreliableExt : NetworkTransform
|
||||||
|
{
|
||||||
|
public Action<Vector3, Vector3> VelRotChangedAction;
|
||||||
|
|
||||||
|
[Header("Snapshot Interpolation")]
|
||||||
|
public Vector3 velocity;
|
||||||
|
public Vector3 angVelocity;
|
||||||
|
|
||||||
|
protected override void Apply(TransformSnapshot interpolated, TransformSnapshot endGoal)
|
||||||
|
{
|
||||||
|
base.Apply(interpolated, endGoal);
|
||||||
|
|
||||||
|
if (!isOwned)
|
||||||
|
{
|
||||||
|
velocity = (transform.position - interpolated.position) / Time.deltaTime;
|
||||||
|
angVelocity = (transform.rotation.eulerAngles - interpolated.rotation.eulerAngles) / Time.deltaTime;
|
||||||
|
VelRotChangedAction?.Invoke(velocity, angVelocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e871e379bd8254748be2fea66b44e5cf
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -100,8 +100,8 @@ public override void OnStartAuthority()
|
|||||||
characterController.enabled = true;
|
characterController.enabled = true;
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
|
|
||||||
TestNTNetworkAuthenticator.AuthRequestMessage authRequestMessage
|
TestNTNetworkAuthenticator.AuthRequestMessage authRequestMessage =
|
||||||
= (TestNTNetworkAuthenticator.AuthRequestMessage)NetworkClient.connection.authenticationData;
|
(TestNTNetworkAuthenticator.AuthRequestMessage)NetworkClient.connection.authenticationData;
|
||||||
if (authRequestMessage.useNinja)
|
if (authRequestMessage.useNinja)
|
||||||
if (TryGetComponent(out NTRCustomSendInterval nt))
|
if (TryGetComponent(out NTRCustomSendInterval nt))
|
||||||
nt.sendIntervalMultiplier = authRequestMessage.multiplier;
|
nt.sendIntervalMultiplier = authRequestMessage.multiplier;
|
||||||
|
@ -49,12 +49,12 @@ public void OnSelectServer(int server)
|
|||||||
|
|
||||||
if (transport is SimpleWebTransport swt)
|
if (transport is SimpleWebTransport swt)
|
||||||
{
|
{
|
||||||
swt.port = 7777;
|
swt.port = 7778;
|
||||||
swt.clientUseWss = true;
|
swt.clientUseWss = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transport is KcpTransport kcp)
|
if (transport is KcpTransport kcp)
|
||||||
kcp.Port = 7777;
|
kcp.Port = 7778;
|
||||||
}
|
}
|
||||||
if (server == 1)
|
if (server == 1)
|
||||||
{
|
{
|
||||||
@ -75,12 +75,12 @@ public void OnSelectServer(int server)
|
|||||||
|
|
||||||
if (transport is SimpleWebTransport swt)
|
if (transport is SimpleWebTransport swt)
|
||||||
{
|
{
|
||||||
swt.port = 27777;
|
swt.port = 27778;
|
||||||
swt.clientUseWss = false;
|
swt.clientUseWss = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transport is KcpTransport kcp)
|
if (transport is KcpTransport kcp)
|
||||||
kcp.Port = 27777;
|
kcp.Port = 27778;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,10 +95,10 @@ public override void Start()
|
|||||||
Application.targetFrameRate = 30;
|
Application.targetFrameRate = 30;
|
||||||
|
|
||||||
if (Transport.active is SimpleWebTransport swt)
|
if (Transport.active is SimpleWebTransport swt)
|
||||||
swt.port = 27777;
|
swt.port = 27778;
|
||||||
|
|
||||||
if (Transport.active is kcp2k.KcpTransport kcp)
|
if (Transport.active is kcp2k.KcpTransport kcp)
|
||||||
kcp.Port = 27777;
|
kcp.Port = 27778;
|
||||||
|
|
||||||
ProcessCmdLineArgs();
|
ProcessCmdLineArgs();
|
||||||
|
|
||||||
@ -176,96 +176,19 @@ void ProcessCmdLineArgs()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Runs on both Server and Client
|
|
||||||
/// </summary>
|
|
||||||
public override void LateUpdate()
|
|
||||||
{
|
|
||||||
base.LateUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Runs on both Server and Client
|
|
||||||
/// </summary>
|
|
||||||
public override void OnDestroy()
|
|
||||||
{
|
|
||||||
base.OnDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Scene Management
|
#region Scene Management
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This causes the server to switch scenes and sets the networkSceneName.
|
|
||||||
/// <para>Clients that connect to this server will automatically switch to this scene. This is called automatically if onlineScene or offlineScene are set, but it can be called from user code to switch scenes again while the game is in progress. This automatically sets clients to be not-ready. The clients must call NetworkClient.Ready() again to participate in the new scene.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="newSceneName"></param>
|
|
||||||
public override void ServerChangeScene(string newSceneName)
|
|
||||||
{
|
|
||||||
base.ServerChangeScene(newSceneName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called from ServerChangeScene immediately before SceneManager.LoadSceneAsync is executed
|
|
||||||
/// <para>This allows server to do work / cleanup / prep before the scene changes.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="newSceneName">Name of the scene that's about to be loaded</param>
|
|
||||||
public override void OnServerChangeScene(string newSceneName) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on the server when a scene is completed loaded, when the scene load was initiated by the server with ServerChangeScene().
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sceneName">The name of the new scene.</param>
|
|
||||||
public override void OnServerSceneChanged(string sceneName) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called from ClientChangeScene immediately before SceneManager.LoadSceneAsync is executed
|
|
||||||
/// <para>This allows client to do work / cleanup / prep before the scene changes.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="newSceneName">Name of the scene that's about to be loaded</param>
|
|
||||||
/// <param name="sceneOperation">Scene operation that's about to happen</param>
|
|
||||||
/// <param name="customHandling">true to indicate that scene loading will be handled through overrides</param>
|
|
||||||
public override void OnClientChangeScene(string newSceneName, SceneOperation sceneOperation, bool customHandling)
|
public override void OnClientChangeScene(string newSceneName, SceneOperation sceneOperation, bool customHandling)
|
||||||
{
|
{
|
||||||
FindObjectOfType<NetworkManagerHUD>().enabled = newSceneName == onlineScene;
|
FindObjectOfType<NetworkManagerHUD>().enabled = newSceneName == onlineScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on clients when a scene has completed loaded, when the scene load was initiated by the server.
|
|
||||||
/// <para>Scene changes can cause player objects to be destroyed. The default implementation of OnClientSceneChanged in the NetworkManager is to add a player object for the connection if no player object exists.</para>
|
|
||||||
/// </summary>
|
|
||||||
public override void OnClientSceneChanged()
|
|
||||||
{
|
|
||||||
base.OnClientSceneChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Server System Callbacks
|
#region Server System Callbacks
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on the server when a new client connects.
|
|
||||||
/// <para>Unity calls this on the Server when a Client connects to the Server. Use an override to tell the NetworkManager what to do when a client connects to the server.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conn">Connection from client.</param>
|
|
||||||
public override void OnServerConnect(NetworkConnectionToClient conn) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on the server when a client is ready.
|
|
||||||
/// <para>The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conn">Connection from client.</param>
|
|
||||||
public override void OnServerReady(NetworkConnectionToClient conn)
|
|
||||||
{
|
|
||||||
base.OnServerReady(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on the server when a client adds a new player with ClientScene.AddPlayer.
|
|
||||||
/// <para>The default implementation for this function creates a new player object from the playerPrefab.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conn">Connection from client.</param>
|
|
||||||
public override void OnServerAddPlayer(NetworkConnectionToClient conn)
|
public override void OnServerAddPlayer(NetworkConnectionToClient conn)
|
||||||
{
|
{
|
||||||
TestNTNetworkAuthenticator.AuthRequestMessage authData = (TestNTNetworkAuthenticator.AuthRequestMessage)conn.authenticationData;
|
TestNTNetworkAuthenticator.AuthRequestMessage authData = (TestNTNetworkAuthenticator.AuthRequestMessage)conn.authenticationData;
|
||||||
@ -301,11 +224,6 @@ public override void OnServerAddPlayer(NetworkConnectionToClient conn)
|
|||||||
NetworkServer.AddPlayerForConnection(conn, player);
|
NetworkServer.AddPlayerForConnection(conn, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on the server when a client disconnects.
|
|
||||||
/// <para>This is called on the Server when a Client disconnects from the Server. Use an override to decide what should happen when a disconnection is detected.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conn">Connection from client.</param>
|
|
||||||
public override void OnServerDisconnect(NetworkConnectionToClient conn)
|
public override void OnServerDisconnect(NetworkConnectionToClient conn)
|
||||||
{
|
{
|
||||||
// remove player name from the HashSet
|
// remove player name from the HashSet
|
||||||
@ -321,31 +239,10 @@ public override void OnServerDisconnect(NetworkConnectionToClient conn)
|
|||||||
base.OnServerDisconnect(conn);
|
base.OnServerDisconnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on server when transport raises an exception.
|
|
||||||
/// <para>NetworkConnection may be null.</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="conn">Connection of the client...may be null</param>
|
|
||||||
/// <param name="exception">Exception thrown from the Transport.</param>
|
|
||||||
public override void OnServerError(NetworkConnectionToClient conn, TransportError transportError, string message) { }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Client System Callbacks
|
#region Client System Callbacks
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on the client when connected to a server.
|
|
||||||
/// <para>The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.</para>
|
|
||||||
/// </summary>
|
|
||||||
public override void OnClientConnect()
|
|
||||||
{
|
|
||||||
base.OnClientConnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on clients when disconnected from a server.
|
|
||||||
/// <para>This is called on the client when it disconnects from the server. Override this function to decide what happens when the client disconnects.</para>
|
|
||||||
/// </summary>
|
|
||||||
public override void OnClientDisconnect()
|
public override void OnClientDisconnect()
|
||||||
{
|
{
|
||||||
Debug.Log("OnClientDisconnect");
|
Debug.Log("OnClientDisconnect");
|
||||||
@ -362,47 +259,15 @@ public override void OnClientDisconnect()
|
|||||||
LoginUI.instance.ToggleButtons(LoginUI.instance.usernameInput.text);
|
LoginUI.instance.ToggleButtons(LoginUI.instance.usernameInput.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on clients when a servers tells the client it is no longer ready.
|
|
||||||
/// <para>This is commonly used when switching scenes.</para>
|
|
||||||
/// </summary>
|
|
||||||
public override void OnClientNotReady() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Called on client when transport raises an exception.</summary>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="exception">Exception thrown from the Transport.</param>
|
|
||||||
public override void OnClientError(TransportError transportError, string message)
|
|
||||||
{
|
|
||||||
Debug.LogError($"OnClientError {transportError} {message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Start & Stop Callbacks
|
#region Start & Stop Callbacks
|
||||||
|
|
||||||
// Since there are multiple versions of StartServer, StartClient and StartHost, to reliably customize
|
|
||||||
// their functionality, users would need override all the versions. Instead these callbacks are invoked
|
|
||||||
// from all versions, so users only need to implement this one case.
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is invoked when a host is started.
|
|
||||||
/// <para>StartHost has multiple signatures, but they all cause this hook to be called.</para>
|
|
||||||
/// </summary>
|
|
||||||
public override void OnStartHost() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is invoked when a server is started - including when a host is started.
|
|
||||||
/// <para>StartServer has multiple signatures, but they all cause this hook to be called.</para>
|
|
||||||
/// </summary>
|
|
||||||
public override void OnStartServer()
|
public override void OnStartServer()
|
||||||
{
|
{
|
||||||
PlayerName.connNames.Clear();
|
PlayerName.connNames.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is invoked when the client is started.
|
|
||||||
/// </summary>
|
|
||||||
public override void OnStartClient()
|
public override void OnStartClient()
|
||||||
{
|
{
|
||||||
NetworkClient.RegisterPrefab(botPrefab);
|
NetworkClient.RegisterPrefab(botPrefab);
|
||||||
@ -412,21 +277,6 @@ public override void OnStartClient()
|
|||||||
NetworkClient.RegisterPrefab(npcNinjaPrefab);
|
NetworkClient.RegisterPrefab(npcNinjaPrefab);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is called when a host is stopped.
|
|
||||||
/// </summary>
|
|
||||||
public override void OnStopHost() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is called when a server is stopped - including when a host is stopped.
|
|
||||||
/// </summary>
|
|
||||||
public override void OnStopServer() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is called when a client is stopped.
|
|
||||||
/// </summary>
|
|
||||||
public override void OnStopClient() { }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user