From a5ab68391738113fae10769dca7df088e3ebad93 Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 15 Mar 2021 19:14:15 +0800 Subject: [PATCH] cleanup --- Assets/Mirror/Runtime/Transport/Transport.cs | 113 ++++--------------- 1 file changed, 23 insertions(+), 90 deletions(-) diff --git a/Assets/Mirror/Runtime/Transport/Transport.cs b/Assets/Mirror/Runtime/Transport/Transport.cs index 996ac63ac..2dbbc3416 100644 --- a/Assets/Mirror/Runtime/Transport/Transport.cs +++ b/Assets/Mirror/Runtime/Transport/Transport.cs @@ -1,47 +1,22 @@ +// Transport Rules +// +// All transports should follow these rules so that they work correctly with mirror: +// * When Monobehaviour is disabled the Transport should not invoke callbacks +// * Callbacks should be invoked on main thread. It is best to do this from LateUpdate +// * Callbacks can be invoked after ServerStop or ClientDisconnect has been called +// * ServerStop or ClientDisconnect can be called by mirror multiple times +// * Available should check the platform and 32 vs 64 bit if the transport only works on some of them +// * GetMaxPacketSize should return size even if transport is not running +// * Default channel should be reliable Channels.DefaultReliable using System; using UnityEngine; namespace Mirror { - /// - /// Abstract transport layer component - /// - /// - ///

- /// Transport Rules - ///

- /// - /// - /// All transports should follow these rules so that they work correctly with mirror - /// - /// - /// When Monobehaviour is disabled the Transport should not invoke callbacks - /// - /// - /// Callbacks should be invoked on main thread. It is best to do this from LateUpdate - /// - /// - /// Callbacks can be invoked after or as been called - /// - /// - /// or can be called by mirror multiple times - /// - /// - /// should check the platform and 32 vs 64 bit if the transport only works on some of them - /// - /// - /// should return size even if transport is not running - /// - /// - /// Default channel should be reliable - /// - /// - ///
+ /// Abstract transport layer component public abstract class Transport : MonoBehaviour { - /// - /// The current transport used by Mirror. - /// + /// The current transport used by Mirror. public static Transport activeTransport; /// @@ -53,47 +28,25 @@ public abstract class Transport : MonoBehaviour /// True if this transport works in the current platform public abstract bool Available(); - #region Client - /// - /// Notify subscribers when this client establish a successful connection to the server - /// callback() - /// + /// Notify subscribers when this client establish a successful connection to the server public Action OnClientConnected = () => Debug.LogWarning("OnClientConnected called with no handler"); - /// - /// Notify subscribers when this client receive data from the server - /// callback(ArraySegment<byte> data, int channel) - /// + /// Notify subscribers when this client receive data from the server public Action, int> OnClientDataReceived = (data, channel) => Debug.LogWarning("OnClientDataReceived called with no handler"); - /// - /// Notify subscribers when this client encounters an error communicating with the server - /// callback(Exception e) - /// + /// Notify subscribers when this client encounters an error communicating with the server public Action OnClientError = (error) => Debug.LogWarning("OnClientError called with no handler"); - /// - /// Notify subscribers when this client disconnects from the server - /// callback() - /// + /// Notify subscribers when this client disconnects from the server public Action OnClientDisconnected = () => Debug.LogWarning("OnClientDisconnected called with no handler"); - /// - /// Determines if we are currently connected to the server - /// - /// True if a connection has been established to the server + /// Determines if we are currently connected to the server public abstract bool ClientConnected(); - /// - /// Establish a connection to a server - /// - /// The IP address or FQDN of the server we are trying to connect to + /// Establish a connection to a server public abstract void ClientConnect(string address); - /// - /// Establish a connection to a server - /// - /// The address of the server we are trying to connect to + /// Establish a connection to a server public virtual void ClientConnect(Uri uri) { // By default, to keep backwards compatibility, just connect to the host @@ -101,36 +54,16 @@ public virtual void ClientConnect(Uri uri) ClientConnect(uri.Host); } - /// - /// Send data to the server - /// - /// The channel to use. 0 is the default channel, - /// but some transports might want to provide unreliable, encrypted, compressed, or any other feature - /// as new channels - /// The data to send to the server. Will be recycled after returning, so either use it directly or copy it internally. This allows for allocation-free sends! + /// Send data to the server over a given channel public abstract void ClientSend(int channelId, ArraySegment segment); - /// - /// Disconnect this client from the server - /// + /// Disconnect this client from the server public abstract void ClientDisconnect(); - #endregion - - #region Server - - - /// - /// Retrieves the address of this server. - /// Useful for network discovery - /// - /// the url at which this server can be reached + /// Get the address of this server. Useful for network discovery public abstract Uri ServerUri(); - /// - /// Notify subscribers when a client connects to this server - /// callback(int connId) - /// + /// Notify subscribers when a client connects to this server public Action OnServerConnected = (connId) => Debug.LogWarning("OnServerConnected called with no handler"); ///