Skip to content

Commit 7cbbff5

Browse files
committed
Fixed issue with custom modules
1 parent b926aa1 commit 7cbbff5

File tree

3 files changed

+141
-8
lines changed

3 files changed

+141
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ crashlytics-build.properties
6464
# Copyrighted Packages
6565
Packages/KSP2_x64
6666
Assets/engine_0v_xenon_dawn*
67+
Managed Testing/
68+
Managed Testing.meta

Assets/KSP2UnityTools/Editor/PartEditor.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Linq;
56
using System.Reflection;
67
using KSP;
78
using UnityEditor;
89
using Cheese.Extensions;
910
using KSP.IO;
1011
using KSP.Modules;
1112
using KSP.Sim.Definitions;
13+
using KSP.Sim.impl;
1214
using Newtonsoft.Json;
1315
using Newtonsoft.Json.UnityConverters;
1416
using Newtonsoft.Json.UnityConverters.Configuration;
@@ -46,15 +48,18 @@ public override void OnInspectorGUI()
4648
if (core == null) return;
4749
// Clear out the serialized part modules and reserialize them
4850
core.data.serializedPartModules.Clear();
49-
foreach (var child in targetGO.GetComponents<PartBehaviourModule>())
51+
foreach (var child in targetGO.GetComponents<Component>())
5052
{
51-
child.GetType().GetMethod("AddDataModules", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(child, new object[] {});
52-
foreach (var data in child.DataModules.Values)
53+
if (!(child is PartBehaviourModule partBehaviourModule)) continue;
54+
var addMethod = child.GetType().GetMethod("AddDataModules", BindingFlags.Instance | BindingFlags.NonPublic) ??
55+
child.GetType().GetMethod("AddDataModules", BindingFlags.Instance | BindingFlags.Public);
56+
addMethod?.Invoke(child, new object[] { });
57+
foreach (var data in partBehaviourModule.DataModules.Values)
5358
{
54-
data.GetType().GetMethod("RebuildDataContext", BindingFlags.Instance | BindingFlags.NonPublic)
55-
?.Invoke(data, new object[] { });
59+
var rebuildMethod = data.GetType().GetMethod("RebuildDataContext", BindingFlags.Instance | BindingFlags.NonPublic) ?? data.GetType().GetMethod("RebuildDataContext", BindingFlags.Instance | BindingFlags.Public);
60+
rebuildMethod?.Invoke(data, new object[] { });
5661
}
57-
core.data.serializedPartModules.Add(new SerializedPartModule(child,false));
62+
core.data.serializedPartModules.Add(new SerializedPartModule(partBehaviourModule,false));
5863
}
5964
var json = IOProvider.ToJson(core);
6065
File.WriteAllText($"{Application.dataPath}/{core.data.partName}.json", json);

Assets/Scenes/SampleScene.unity

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ GameObject:
641641
- component: {fileID: 2045490031}
642642
- component: {fileID: 2045490030}
643643
- component: {fileID: 2045490029}
644+
- component: {fileID: 2045490035}
644645
m_Layer: 0
645646
m_Name: TestPart
646647
m_TagString: Untagged
@@ -1304,9 +1305,13 @@ MonoBehaviour:
13041305
ModuleData:
13051306
- Name: Data_Fairing
13061307
Data:
1307-
- Name: PartComponentModule_CompoundPart
1308+
- Name: PartComponentModule_DeployableControlSurface
13081309
ModuleData:
1309-
- Name: Data_CompoundPart
1310+
- Name: Data_LiftingSurface
1311+
Data:
1312+
- Name: Data_ControlSurface
1313+
Data:
1314+
- Name: Data_DeployableControlSurface
13101315
Data:
13111316
resourceSummary:
13121317
Consumes:
@@ -1339,3 +1344,124 @@ MonoBehaviour:
13391344
PickUpPointOffset: {x: 0, y: 0, z: 0}
13401345
PickupRotationPointOffset: {x: 0, y: 0, z: 0}
13411346
legacyModules:
1347+
--- !u!114 &2045490035
1348+
MonoBehaviour:
1349+
m_ObjectHideFlags: 0
1350+
m_CorrespondingSourceObject: {fileID: 0}
1351+
m_PrefabInstance: {fileID: 0}
1352+
m_PrefabAsset: {fileID: 0}
1353+
m_GameObject: {fileID: 2045490027}
1354+
m_Enabled: 1
1355+
m_EditorHideFlags: 0
1356+
m_Script: {fileID: 235333479, guid: 3046f413347669c40bed1fd7b4c64202, type: 3}
1357+
m_Name:
1358+
m_EditorClassIdentifier:
1359+
dataLiftingSurface:
1360+
omnidirectional: 1
1361+
liftCurve:
1362+
fCurve:
1363+
serializedVersion: 2
1364+
m_Curve:
1365+
- serializedVersion: 3
1366+
time: 0
1367+
value: 0
1368+
inSlope: 0
1369+
outSlope: 0
1370+
tangentMode: 0
1371+
weightedMode: 0
1372+
inWeight: 0
1373+
outWeight: 0
1374+
m_PreInfinity: 2
1375+
m_PostInfinity: 2
1376+
m_RotationOrder: 4
1377+
_minTime: 3.4028235e+38
1378+
_maxTime: -3.4028235e+38
1379+
liftMachCurve:
1380+
fCurve:
1381+
serializedVersion: 2
1382+
m_Curve:
1383+
- serializedVersion: 3
1384+
time: 0
1385+
value: 0
1386+
inSlope: 0
1387+
outSlope: 0
1388+
tangentMode: 0
1389+
weightedMode: 0
1390+
inWeight: 0
1391+
outWeight: 0
1392+
m_PreInfinity: 2
1393+
m_PostInfinity: 2
1394+
m_RotationOrder: 4
1395+
_minTime: 3.4028235e+38
1396+
_maxTime: -3.4028235e+38
1397+
dragCurve:
1398+
fCurve:
1399+
serializedVersion: 2
1400+
m_Curve:
1401+
- serializedVersion: 3
1402+
time: 0
1403+
value: 0
1404+
inSlope: 0
1405+
outSlope: 0
1406+
tangentMode: 0
1407+
weightedMode: 0
1408+
inWeight: 0
1409+
outWeight: 0
1410+
m_PreInfinity: 2
1411+
m_PostInfinity: 2
1412+
m_RotationOrder: 4
1413+
_minTime: 3.4028235e+38
1414+
_maxTime: -3.4028235e+38
1415+
dragMachCurve:
1416+
fCurve:
1417+
serializedVersion: 2
1418+
m_Curve:
1419+
- serializedVersion: 3
1420+
time: 0
1421+
value: 0
1422+
inSlope: 0
1423+
outSlope: 0
1424+
tangentMode: 0
1425+
weightedMode: 0
1426+
inWeight: 0
1427+
outWeight: 0
1428+
m_PreInfinity: 2
1429+
m_PostInfinity: 2
1430+
m_RotationOrder: 4
1431+
_minTime: 3.4028235e+38
1432+
_maxTime: -3.4028235e+38
1433+
liftingSurfaceCurve: Default
1434+
transformDir: 2
1435+
transformSign: 1
1436+
transformName:
1437+
nodeEnabled: 0
1438+
attachNodeName:
1439+
deflectionLiftCoeff: 1.5
1440+
perpendicularOnly: 0
1441+
useInternalDragModel: 1
1442+
CoPOffset: {x: 0, y: 0, z: 0}
1443+
baseTransform: {fileID: 0}
1444+
debugThis: 0
1445+
dataCtrlSurface:
1446+
IsCtrlSurfaceActive: 0
1447+
LiftingCtrlSurfaceArea: 0
1448+
CoPressureCtrlSurfaceOffset: {x: 0, y: 0, z: 0}
1449+
CtrlSurfacePivotOffset: {x: 0, y: 0, z: 0}
1450+
CtrlTransformDir: 2
1451+
CtrlTransformRotAxis: 0
1452+
CtrlTransformSign: -1
1453+
CtrlSurfacePivotTransformName: obj_ctrlSrf
1454+
CtrlSurfaceRange: 15
1455+
CtrlSurfaceArea: 0.5
1456+
UseExponentialSpeed: 0
1457+
ActuatorSpeedNormalScale: 30
1458+
MirrorDeploy: 0
1459+
MeshAreaLiftMultiplier: 0.25
1460+
DisableLiftingSurfaceForce: 0
1461+
ApplyLiftSurfaceForceAtBase: 0
1462+
ApplyLiftSurfaceForceAtPivotMidpoint: 0
1463+
_ctrlSurface: {fileID: 0}
1464+
_deflectionDirection: 1
1465+
_referenceXform: {fileID: 0}
1466+
animator: {fileID: 0}
1467+
dataDeployableControlSurface: {}

0 commit comments

Comments
 (0)