forked from Unity-Technologies/com.unity.netcode.gameobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkObjectLabel.cs
More file actions
73 lines (58 loc) · 1.45 KB
/
NetworkObjectLabel.cs
File metadata and controls
73 lines (58 loc) · 1.45 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Unity.Netcode;
using UnityEngine;
public class NetworkObjectLabel : NetworkBehaviour
{
public static bool GlobalVisibility = true;
private TextMesh m_ObjectLabel;
private MeshRenderer m_Renderer;
private bool m_IsLabelVisible = true;
public void SetLabelVisibility(bool isVisiable)
{
m_IsLabelVisible = isVisiable;
ShowHideLabel(m_IsLabelVisible);
}
private void ShowHideLabel(bool isVisible)
{
if (m_Renderer == null)
{
m_Renderer = GetComponent<MeshRenderer>();
}
if (m_Renderer != null)
{
m_Renderer.enabled = isVisible;
}
}
private void OnEnable()
{
if (m_IsLabelVisible)
{
ShowHideLabel(GlobalVisibility);
}
}
private void OnDisable()
{
if (m_IsLabelVisible)
{
ShowHideLabel(false);
}
}
public override void OnNetworkSpawn()
{
if (m_ObjectLabel == null)
{
m_ObjectLabel = GetComponent<TextMesh>();
}
m_ObjectLabel.text = NetworkObject.NetworkObjectId.ToString();
SetLabelVisibility(GlobalVisibility);
base.OnNetworkSpawn();
}
public override void OnNetworkDespawn()
{
if (m_ObjectLabel == null)
{
m_ObjectLabel = GetComponent<TextMesh>();
}
m_ObjectLabel.text = "None";
base.OnNetworkDespawn();
}
}