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.
56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
1 week ago
|
using System;
|
||
|
using Unity.Netcode;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
|
||
|
{
|
||
|
public class ClientPlayerAvatar : NetworkBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
ClientPlayerAvatarRuntimeCollection m_PlayerAvatars;
|
||
|
|
||
|
public static event Action<ClientPlayerAvatar> LocalClientSpawned;
|
||
|
|
||
|
public static event Action LocalClientDespawned;
|
||
|
|
||
|
public override void OnNetworkSpawn()
|
||
|
{
|
||
|
name = "PlayerAvatar" + OwnerClientId;
|
||
|
|
||
|
if (IsClient && IsOwner)
|
||
|
{
|
||
|
LocalClientSpawned?.Invoke(this);
|
||
|
}
|
||
|
|
||
|
if (m_PlayerAvatars)
|
||
|
{
|
||
|
m_PlayerAvatars.Add(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override void OnNetworkDespawn()
|
||
|
{
|
||
|
if (IsClient && IsOwner)
|
||
|
{
|
||
|
LocalClientDespawned?.Invoke();
|
||
|
}
|
||
|
|
||
|
RemoveNetworkCharacter();
|
||
|
}
|
||
|
|
||
|
public override void OnDestroy()
|
||
|
{
|
||
|
base.OnDestroy();
|
||
|
RemoveNetworkCharacter();
|
||
|
}
|
||
|
|
||
|
void RemoveNetworkCharacter()
|
||
|
{
|
||
|
if (m_PlayerAvatars)
|
||
|
{
|
||
|
m_PlayerAvatars.Remove(this);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|