/
TorchItemRep.cs
87 lines (78 loc) · 1.9 KB
/
TorchItemRep.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Facepunch;
using System;
using uLink;
using UnityEngine;
public class TorchItemRep : ItemRepresentation
{
public GameObject _myLight;
public GameObject _myLightPrefab;
private const bool defaultLit = false;
private bool lit;
public AudioClip StrikeSound;
private void KillLight()
{
if (this._myLight != null)
{
UnityEngine.Object.Destroy(this._myLight);
this._myLight = null;
}
}
protected void OnDestroy()
{
this.KillLight();
base.OnDestroy();
}
[RPC]
protected void OnStatus(bool on)
{
if (on != this.lit)
{
if (on)
{
this.RepIgnite();
}
else
{
this.RepExtinguish();
}
this.lit = on;
}
}
public void RepExtinguish()
{
if (this.lit)
{
this.lit = false;
this.KillLight();
}
}
public void RepIgnite()
{
if (!this.lit)
{
this.lit = true;
this.StrikeSound.Play(base.transform.position, (float) 1f, (float) 2f, (float) 8f);
this._myLight = base.muzzle.InstantiateAsChild(this._myLightPrefab, false);
}
}
private void ServerRPC_Status(bool lit)
{
uLink.RPCMode othersExceptOwner;
Facepunch.NetworkView networkView = base.networkView;
if (!lit)
{
othersExceptOwner = uLink.RPCMode.OthersExceptOwner;
}
else
{
othersExceptOwner = uLink.RPCMode.OthersExceptOwnerBuffered;
}
networkView.RPC<bool>("OnStatus", othersExceptOwner, lit);
this.lit = lit;
}
protected void uLink_OnNetworkInstantiate(uLink.NetworkMessageInfo info)
{
base.uLink_OnNetworkInstantiate(info);
this.OnStatus(false);
}
}