using FishNet.Transporting;
using FishNet.Transporting.Multipass;
using UnityEngine;
namespace FishNet.Managing.Transporting
{
///
/// Communicates with the Transport to send and receive data.
///
public sealed partial class TransportManager : MonoBehaviour
{
#region Public.
///
/// Returns IsLocalTransport for the current transport.
///
public bool IsLocalTransport(int connectionId) => (Transport == null) ? false : Transport.IsLocalTransport(connectionId);
#endregion
///
/// Gets transport on index.
/// Commonly index will be 0 unless using Multipass.
///
///
public Transport GetTransport(int index)
{
//If using multipass try to find the correct transport.
if (Transport is Multipass mp)
{
return mp.GetTransport(index);
}
//Not using multipass.
else
{
return Transport;
}
}
///
/// Gets transport of type T.
///
/// Returns the found transport which is of type T. Returns default of T if not found.
public T GetTransport() where T : Transport
{
//If using multipass try to find the correct transport.
if (Transport is Multipass mp)
{
if (typeof(T) == typeof(Multipass))
return (T)(object)mp;
else
return mp.GetTransport();
}
//Not using multipass.
else
{
if (Transport.GetType() == typeof(T))
return (T)(object)Transport;
else
return default(T);
}
}
}
}