optimizing network stuff
This commit is contained in:
@@ -1,47 +1,46 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Unity.Collections;
|
||||
using Unity.Netcode;
|
||||
using RebootKit.Engine.Network;
|
||||
using UnityEngine;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootKit.Engine.Main {
|
||||
public abstract class Game : NetworkBehaviour {
|
||||
public abstract class Game : MonoBehaviour {
|
||||
static readonly Logger s_GameLogger = new Logger(nameof(Game));
|
||||
|
||||
[SerializeField] NetworkPlayerController m_PlayerControllerPrefab;
|
||||
|
||||
public NetworkPlayerController LocalPlayerController { get; internal set; }
|
||||
|
||||
protected virtual void Awake() {
|
||||
LocalPlayerController = Instantiate(m_PlayerControllerPrefab, transform);
|
||||
}
|
||||
|
||||
// Server only callbacks
|
||||
//
|
||||
// @MARK: Server
|
||||
//
|
||||
protected virtual void OnPlayerBecameReady(ulong clientID) {
|
||||
}
|
||||
|
||||
// Event callbacks
|
||||
public virtual void OnClientConnected(ulong clientID) {
|
||||
s_GameLogger.Info($"Client {clientID} connected");
|
||||
}
|
||||
|
||||
public virtual void OnClientDisconnected(ulong clientID) {
|
||||
s_GameLogger.Info($"Client {clientID} disconnected");
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: Chat
|
||||
//
|
||||
protected virtual void OnChatMessage(string message) {
|
||||
s_GameLogger.Info($"Chat: {message}");
|
||||
}
|
||||
|
||||
// NGO callbacks
|
||||
public override void OnNetworkSpawn() {
|
||||
base.OnNetworkSpawn();
|
||||
RR.GameInstance = this;
|
||||
}
|
||||
|
||||
public override void OnNetworkDespawn() {
|
||||
base.OnNetworkDespawn();
|
||||
RR.GameInstance = null;
|
||||
}
|
||||
|
||||
// Chat
|
||||
[Rpc(SendTo.Server)]
|
||||
public void SendChatMessageRpc(string message) {
|
||||
PrintChatMessageClientRpc(message);
|
||||
}
|
||||
|
||||
[ClientRpc(Delivery = RpcDelivery.Reliable)]
|
||||
void PrintChatMessageClientRpc(string message) {
|
||||
OnChatMessage(message);
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: Player Ready State
|
||||
//
|
||||
internal void PlayerBecameReady(ulong clientID) {
|
||||
if (!IsServer) {
|
||||
if (!RR.IsServer()) {
|
||||
s_GameLogger.Error("PlayerBecameReady called on client, but this should only be called on the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user