/
AssignAxisGroup.cs
67 lines (63 loc) · 2.06 KB
/
AssignAxisGroup.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
using Expansions.Serenity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace PropellerPithAndRotorTorque
{
/// <summary>
/// This is used to assign Main Throttle to RPM limit automatically
/// </summary>
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
class AssignAxisGroup : MonoBehaviour
{
void Awake()
{
GameEvents.onEditorPartEvent.Add(OnPartEvent);
}
void OnDestroy()
{
GameEvents.onEditorPartEvent.Remove(OnPartEvent);
}
private void OnPartEvent(ConstructionEventType t, Part p)
{
if (t == ConstructionEventType.PartCreated)
// if (PPARTMgr.ROTOR_NAMES.Contains(p.partName))
AssignAxis(p);
}
private static void AssignAxis(Part p)
{
#if DEBUG
Debug.Log("Rotor added");
#endif
List<ModuleRoboticServoRotor> list = p.FindModulesImplementing<ModuleRoboticServoRotor>();
int count = list.Count;
while (count-- > 0)
{
ModuleRoboticServoRotor partModule = list[count];
int count2 = partModule.Fields.Count;
while (count2-- > 0)
{
BaseAxisField baseAxisField = partModule.Fields[count2] as BaseAxisField;
if (baseAxisField == null)
{
continue;
}
if (baseAxisField.FieldInfo.FieldType == typeof(float) && baseAxisField.name == "rpmLimit")
{
#if DEBUG
Debug.Log("Found a baseAxisField");
#endif
baseAxisField.axisGroup = KSPAxisGroup.MainThrottle;
((KSPAxisField)baseAxisField.Attribute).axisMode = KSPAxisMode.Absolute;
#if DEBUG
Debug.Log("Updated axis group and mode");
#endif
}
}
}
}
}
}