You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.6 KiB
C#

//Shady
using Fusion;
using System;
using UnityEngine;
using StarterAssets;
using Fusion.Sockets;
using DedicatedServer.Utils;
using System.Threading.Tasks;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
#pragma warning disable UNT0006
[ScriptHelp(BackColor = ScriptHeaderBackColor.Red)]
public class ClientSessionHandler : Fusion.Behaviour, INetworkRunnerCallbacks
{
//===================================================
// FIELDS
//===================================================
[SerializeField] UICanvasControllerInput _mobileInput = null;
//===================================================
// PROPERTIES
//===================================================
public UICanvasControllerInput MobileInput => _mobileInput;
public Action<NetworkRunner, NetworkInput> OnInputAction = null;
//===================================================
// METHODS
//===================================================
private void Awake()
{
GameLog.ShowMessage("Client Session Handler Instantiated!");
if(_mobileInput == null)
_mobileInput = GetComponentInChildren<UICanvasControllerInput>();
_mobileInput.gameObject.SetActive(false);
}//Awake() end
//===================================================
// USED CALLBACKS
//===================================================
public void OnConnectedToServer(NetworkRunner runner) => _mobileInput.gameObject.SetActive(Application.isMobilePlatform);
public void OnInput(NetworkRunner runner, NetworkInput input) => OnInputAction?.Invoke(runner, input);
public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason)
{
GameLog.ShowMessage(runner.ToString() + " Whaye Shutdown " + shutdownReason);
if(shutdownReason == ShutdownReason.Ok)
return;
_mobileInput.gameObject.SetActive(false);
if (Application.isPlaying)
{
GameLog.ShowMessage("OnShutdown" + shutdownReason);
FadeSystem.Instance.FadeIn(async ()=>
{
SceneManager.LoadScene((int)SceneDefs.MENU, LoadSceneMode.Single);
await Task.Delay(100);
GameManager.Instance.Splash();
});
}//if end
}//OnShutDown() end
public void OnDisconnectedFromServer(NetworkRunner runner)
{
Debug.Log("OnDisconnectedFromServer");
_mobileInput.gameObject.SetActive(false);
runner.Shutdown();
if (Application.isPlaying)
FadeSystem.Instance.FadeIn(()=>SceneManager.LoadScene((int)SceneDefs.MENU, LoadSceneMode.Single));
}//OnDisconnectedFromServer() end
public void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason)
{
Debug.Log("OnConnectFailed");
_mobileInput.gameObject.SetActive(false);
runner.Shutdown();
if (Application.isPlaying)
FadeSystem.Instance.FadeIn(()=>SceneManager.LoadScene((int)SceneDefs.MENU, LoadSceneMode.Single));
}//OnConnectFailed() end
//===================================================
// UNUSED CALLBACKS
//===================================================
public void OnObjectExitAOI(NetworkRunner runner, NetworkObject obj, PlayerRef player){}
public void OnObjectEnterAOI(NetworkRunner runner, NetworkObject obj, PlayerRef player){}
public void OnPlayerJoined(NetworkRunner runner, PlayerRef player){}
public void OnPlayerLeft(NetworkRunner runner, PlayerRef player){}
public void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input){}
public void OnDisconnectedFromServer(NetworkRunner runner, NetDisconnectReason reason){}
public void OnConnectRequest(NetworkRunner runner, NetworkRunnerCallbackArgs.ConnectRequest request, byte[] token){}
public void OnUserSimulationMessage(NetworkRunner runner, SimulationMessagePtr message){}
public void OnSessionListUpdated(NetworkRunner runner, List<SessionInfo> sessionList){}
public void OnCustomAuthenticationResponse(NetworkRunner runner, Dictionary<string, object> data){}
public void OnHostMigration(NetworkRunner runner, HostMigrationToken hostMigrationToken){}
public void OnReliableDataReceived(NetworkRunner runner, PlayerRef player, ReliableKey key, ArraySegment<byte> data){}
public void OnReliableDataProgress(NetworkRunner runner, PlayerRef player, ReliableKey key, float progress){}
public void OnSceneLoadDone(NetworkRunner runner){}
public void OnSceneLoadStart(NetworkRunner runner){}
}//class end