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.
73 lines
3.0 KiB
C#
73 lines
3.0 KiB
C#
using Fusion;
|
|
using Fusion.Sockets;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using CnControls;
|
|
using System;
|
|
|
|
public struct CarNetworkInput : INetworkInput
|
|
{
|
|
public float Horizontal;
|
|
public float Vertical;
|
|
public bool NOS;
|
|
}
|
|
|
|
public class FusionInputProvider : SimulationBehaviour, INetworkRunnerCallbacks
|
|
{
|
|
void OnEnable()
|
|
{
|
|
if (Runner != null)
|
|
Runner.AddCallbacks(this);
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
if (Runner != null)
|
|
Runner.RemoveCallbacks(this);
|
|
}
|
|
|
|
// ← This is the one that Fusion calls each tick to collect your input
|
|
public void OnInput(NetworkRunner runner, NetworkInput input)
|
|
{
|
|
var data = default(CarNetworkInput);
|
|
|
|
// read your steering/throttle
|
|
data.Horizontal = CnInputManager.GetAxis("Horizontal");
|
|
data.Vertical = CnInputManager.GetAxis("Vertical");
|
|
// grab the NOS state from the local player's spawned object
|
|
if (runner.TryGetPlayerObject(runner.LocalPlayer, out var playerObj))
|
|
{
|
|
var nosCtrl = playerObj.GetComponentInChildren<NOSController>();
|
|
// use the networked CurrentNOS > 0f as “boost is active”
|
|
data.NOS = nosCtrl != null && nosCtrl.CurrentNOS > 0f;
|
|
}
|
|
else
|
|
{
|
|
data.NOS = false;
|
|
}
|
|
|
|
input.Set(data);
|
|
}
|
|
|
|
// ─── All other callbacks are stubs ───
|
|
|
|
public void OnPlayerJoined(NetworkRunner runner, PlayerRef player) { }
|
|
public void OnPlayerLeft(NetworkRunner runner, PlayerRef player) { }
|
|
public void OnConnectedToServer(NetworkRunner runner) { }
|
|
public void OnConnectRequest(NetworkRunner runner, NetworkRunnerCallbackArgs.ConnectRequest req, byte[] tok) { }
|
|
public void OnConnectFailed(NetworkRunner runner, NetAddress addr, NetConnectFailedReason reason) { }
|
|
public void OnDisconnectedFromServer(NetworkRunner runner, NetDisconnectReason reason) { }
|
|
public void OnHostMigration(NetworkRunner runner, HostMigrationToken token) { }
|
|
public void OnSessionListUpdated(NetworkRunner runner, List<SessionInfo> sessionList) { }
|
|
public void OnCustomAuthenticationResponse(NetworkRunner runner, Dictionary<string, object> data) { }
|
|
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 OnUserSimulationMessage(NetworkRunner runner, SimulationMessagePtr message) { }
|
|
public void OnShutdown(NetworkRunner runner, ShutdownReason reason) { }
|
|
public void OnSceneLoadStart(NetworkRunner runner) { }
|
|
public void OnSceneLoadDone(NetworkRunner runner) { }
|
|
public void OnObjectEnterAOI(NetworkRunner runner, NetworkObject obj, PlayerRef player) { }
|
|
public void OnObjectExitAOI(NetworkRunner runner, NetworkObject obj, PlayerRef player) { }
|
|
public void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input) { }
|
|
}
|