-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientPlayerAvatar.cs
55 lines (45 loc) · 1.23 KB
/
ClientPlayerAvatar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
}
}
}
}