68 lines
1.4 KiB
C#
68 lines
1.4 KiB
C#
using FishNet;
|
|
using FishNet.Transporting;
|
|
using FishNet.Transporting.Tugboat;
|
|
using ParrelSync;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using Utils;
|
|
|
|
public class ConnectionStarter : MonoBehaviour
|
|
{
|
|
public enum ConnectionType
|
|
{
|
|
Host,
|
|
Client
|
|
}
|
|
|
|
[SerializeField] private ConnectionType _connectionType;
|
|
|
|
private Tugboat _tugboat;
|
|
|
|
private void Awake()
|
|
{
|
|
if (TryGetComponent(out Tugboat tug))
|
|
{
|
|
_tugboat = tug;
|
|
}
|
|
else
|
|
{
|
|
GameLogger.LogError("Tugboat not found for connection type: " + _connectionType);
|
|
return;
|
|
}
|
|
#if UNITY_EDITOR
|
|
if (_connectionType == ConnectionType.Host)
|
|
{
|
|
if (ClonesManager.IsClone())
|
|
{
|
|
_tugboat.StartConnection(false);
|
|
}
|
|
else
|
|
{
|
|
_tugboat.StartConnection(true);
|
|
_tugboat.StartConnection(false);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
_tugboat.StartConnection(false);
|
|
|
|
#endif
|
|
#if !UNITY_EDITOR
|
|
_tugboat.StartConnection(true);
|
|
#endif
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
InstanceFinder.ClientManager.OnClientConnectionState += OnClientConnectionState;
|
|
}
|
|
|
|
private void OnClientConnectionState(ClientConnectionStateArgs args)
|
|
{
|
|
#if UNITY_EDITOR
|
|
if (args.ConnectionState == LocalConnectionState.Stopping)
|
|
EditorApplication.isPlaying = false;
|
|
#endif
|
|
}
|
|
} |