forked from ihsoft/KAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKASModuleSuctionCup.cs
More file actions
80 lines (70 loc) · 2.4 KB
/
KASModuleSuctionCup.cs
File metadata and controls
80 lines (70 loc) · 2.4 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
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace KAS
{
public class KASModuleSuctionCup : KASModuleAttachCore
{
[KSPField]
public float breakForce = 10;
[KSPField]
public string attachSndPath = "KAS/Sounds/attach";
[KSPField]
public string detachSndPath = "KAS/Sounds/detach";
public FXGroup fxSndAttach, fxSndDetach;
//Info
[KSPField(guiActive = true, guiName = "State", guiFormat = "S")]
public string state = "Off";
public override string GetInfo()
{
string info = base.GetInfo();
info += "---- Suction Cup ----";
info += "\n";
info += "Break Force : " + breakForce;
return info;
}
public override void OnStart(StartState state)
{
base.OnStart(state);
if (state == StartState.Editor || state == StartState.None) return;
KAS_Shared.createFXSound(this.part, fxSndAttach, attachSndPath, false);
KAS_Shared.createFXSound(this.part, fxSndDetach, detachSndPath, false);
}
public void OnAttachPart(Part targetPart)
{
AttachSuction(targetPart, breakForce);
}
public void AttachSuction(Part partToAttach, float breakforce)
{
AttachFixed(partToAttach, breakforce);
Events["ContextMenuDetach"].guiActiveUnfocused = true;
Events["ContextMenuDetach"].guiActive = true;
//Update context menu info
state = "Attached to : " + partToAttach.partInfo.title;
//Sound
fxSndAttach.audio.Play();
}
public void DetachSuction()
{
Detach();
Events["ContextMenuDetach"].guiActiveUnfocused = false;
Events["ContextMenuDetach"].guiActive = false;
state = "Idle";
if (attachMode.FixedJoint) fxSndDetach.audio.Play();
}
[KSPEvent(name = "ContextMenuDetach", active = true, guiActive = false, guiActiveUnfocused = false, guiName = "Detach")]
public void ContextMenuDetach()
{
DetachSuction();
}
[KSPAction("Detach")]
public void ActionGroupDetach(KSPActionParam param)
{
if (!this.part.packed)
{
DetachSuction();
}
}
}
}