-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathItemBlasterPowerCell.cs
61 lines (51 loc) · 2.61 KB
/
ItemBlasterPowerCell.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
using UnityEngine;
using ThunderRoad;
namespace TOR {
public class ItemBlasterPowerCell : ThunderBehaviour {
protected Item item;
protected ItemModuleBlasterPowerCell module;
AudioSource audio;
ParticleSystem particle;
bool holdingLeft;
bool holdingRight;
protected void Awake() {
item = this.GetComponent<Item>();
module = item.data.GetModule<ItemModuleBlasterPowerCell>();
audio = item.GetCustomReference("Particle").GetComponent<AudioSource>();
particle = item.GetCustomReference("Particle").GetComponent<ParticleSystem>();
for (int i = 0, l = item.collisionHandlers.Count; i < l; i++) {
item.collisionHandlers[i].OnCollisionStartEvent += CollisionHandler;
}
item.OnGrabEvent += OnGrabEvent;
item.OnUngrabEvent += OnUngrabEvent;
var projectileData = Catalog.GetData<ProjectileData>(module.projectileID, true);
if (projectileData != null) {
var mesh = item.GetCustomReference("Mesh").GetComponent<MeshRenderer>();
mesh.materials[0].SetColor("_BaseColor", Utils.UpdateHue(mesh.materials[0].GetColor("_BaseColor"), projectileData.boltHue));
if (particle) {
var main = particle.main;
main.startColor = Utils.UpdateHue(main.startColor.color, projectileData.boltHue);
}
}
}
public void OnGrabEvent(Handle handle, RagdollHand interactor) {
holdingRight |= interactor.playerHand == Player.local.handRight;
holdingLeft |= interactor.playerHand == Player.local.handLeft;
}
public void OnUngrabEvent(Handle handle, RagdollHand interactor, bool throwing) {
holdingRight &= interactor.playerHand != Player.local.handRight;
holdingLeft &= interactor.playerHand == Player.local.handLeft;
}
void CollisionHandler(CollisionInstance collisionInstance) {
try {
if (collisionInstance.sourceColliderGroup.name == "CollisionBlasterPowerCell" && collisionInstance.targetColliderGroup.name == "CollisionBlasterRefill") {
collisionInstance.targetColliderGroup.transform.root.SendMessage("RechargeFromPowerCell", module.projectileID);
Utils.PlayParticleEffect(particle);
Utils.PlayHaptic(holdingLeft, holdingRight, Utils.HapticIntensity.Major);
Utils.PlaySound(audio, module.audioAsset, item);
}
}
catch { }
}
}
}