forked from Facepunch/Rust.Community
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunityEntity.cs
More file actions
65 lines (55 loc) · 1.82 KB
/
Copy pathCommunityEntity.cs
File metadata and controls
65 lines (55 loc) · 1.82 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
using Facepunch;
using ProtoBuf;
using System.Collections.Generic;
using UnityEngine;
public partial class CommunityEntity : PointEntity
{
public static CommunityEntity ServerInstance = null;
public static CommunityEntity ClientInstance = null;
// Inside shared class so it stays serialized when switching defines
public GameObject[] OverallPanels;
public Canvas[] AllCanvases;
public override void InitShared()
{
if ( isServer ) ServerInstance = this;
else ClientInstance = this;
base.InitShared();
}
public override void DestroyShared()
{
base.DestroyShared();
if ( isServer ) ServerInstance = null;
else ClientInstance = null;
}
#if CLIENT
protected override void ClientInit(Entity info)
{
base.ClientInit(info);
UpdateCanvasesVisibility();
}
#endif
#if SERVER
// This mainly exists for our ServerRPC overload generator so this specific overload can exist
public void SendDestroyUIs(BasePlayer player, List<string> uiPanels)
{
using var destroyUi = Pool.Get<ProtoBuf.CommunityEntity_DestroyUIs>();
destroyUi.list = Pool.Get<List<string>>();
for(int i = 0; i < uiPanels.Count; i++)
{
destroyUi.list.Add(uiPanels[i]);
}
ClientRPC(RpcTarget.Player("DestroyUIs", player), destroyUi);
}
// Added alternative overload; plugins can have a static array with all UIs they want to destroy predefined
public void SendDestroyUIs(BasePlayer player, string[] uiPanels)
{
using var destroyUi = Pool.Get<ProtoBuf.CommunityEntity_DestroyUIs>();
destroyUi.list = Pool.Get<List<string>>();
for (int i = 0; i < uiPanels.Length; i++)
{
destroyUi.list.Add(uiPanels[i]);
}
ClientRPC(RpcTarget.Player("DestroyUIs", player), destroyUi);
}
#endif
}