示例
大厅空了就把场地复位(重置比分、关灯、收回道具)。用玩家加入/离开事件统计人数。
using UnityEngine;
using Cilbox;
using Aeloria;
using Aeloria.Scripts.Networking.NetworkedAvatar;
[Cilboxable]
public class ArenaReset : MonoBehaviour
{
AeloriaNetworkShim net;
int players;
void Start()
{
net = GetComponent<AeloriaNetworkShim>();
net.PlayerJoined += OnJoined;
net.PlayerLeft += OnLeft;
}
void OnDestroy()
{
if (net == null) return;
net.PlayerJoined -= OnJoined;
net.PlayerLeft -= OnLeft;
}
void OnJoined(AeloriaNetworkPlayer player) { players++; }
void OnLeft(AeloriaNetworkPlayer player)
{
players--;
if (players <= 0) ResetArena();
}
void ResetArena()
{
// 在这里复位场地
}
}
net.IsOwnedLocallyOnServer 判断即可;