forked from Unity-Technologies/com.unity.netcode.gameobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerHostClientText.cs
More file actions
70 lines (61 loc) · 1.6 KB
/
ServerHostClientText.cs
File metadata and controls
70 lines (61 loc) · 1.6 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
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
public class ServerHostClientText : NetworkBehaviour
{
[SerializeField]
private Text m_DisplayText;
private Color m_Color;
private Color m_ColorAlpha;
private Vector3 m_LocalPosition;
public void SetColor(Color color)
{
m_Color = color;
m_ColorAlpha = color;
m_ColorAlpha.a = 0.35f;
}
private void Awake()
{
m_LocalPosition = transform.localPosition;
}
private void Start()
{
Screen.SetResolution((int)(Screen.currentResolution.width * 0.40f), (int)(Screen.currentResolution.height * 0.40f), false);
if (m_DisplayText != null)
{
m_DisplayText.text = string.Empty;
SetColor(m_DisplayText.color);
}
}
public override void OnNetworkSpawn()
{
if (m_DisplayText != null)
{
if (NetworkManager.IsServer)
{
m_DisplayText.text = NetworkManager.IsHost ? "Host" : "Server";
}
else if (NetworkManager.IsClient)
{
m_DisplayText.text = $"Client-{NetworkManager.LocalClientId}";
}
}
transform.localPosition = m_LocalPosition;
//m_DisplayText.rectTransform.position = new Vector3(0.0f, 30.0f, 0.0f);
}
private void OnGUI()
{
if (!IsSpawned)
{
return;
}
if (Application.isFocused)
{
m_DisplayText.color = m_Color;
}
else
{
m_DisplayText.color = m_ColorAlpha;
}
}
}