Skip to content

Commit

Permalink
Fixed issue with custom modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Mar 28, 2023
1 parent b926aa1 commit 7cbbff5
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ crashlytics-build.properties
# Copyrighted Packages
Packages/KSP2_x64
Assets/engine_0v_xenon_dawn*
Managed Testing/
Managed Testing.meta
17 changes: 11 additions & 6 deletions Assets/KSP2UnityTools/Editor/PartEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using KSP;
using UnityEditor;
using Cheese.Extensions;
using KSP.IO;
using KSP.Modules;
using KSP.Sim.Definitions;
using KSP.Sim.impl;
using Newtonsoft.Json;
using Newtonsoft.Json.UnityConverters;
using Newtonsoft.Json.UnityConverters.Configuration;
Expand Down Expand Up @@ -46,15 +48,18 @@ public override void OnInspectorGUI()
if (core == null) return;
// Clear out the serialized part modules and reserialize them
core.data.serializedPartModules.Clear();
foreach (var child in targetGO.GetComponents<PartBehaviourModule>())
foreach (var child in targetGO.GetComponents<Component>())
{
child.GetType().GetMethod("AddDataModules", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(child, new object[] {});
foreach (var data in child.DataModules.Values)
if (!(child is PartBehaviourModule partBehaviourModule)) continue;
var addMethod = child.GetType().GetMethod("AddDataModules", BindingFlags.Instance | BindingFlags.NonPublic) ??
child.GetType().GetMethod("AddDataModules", BindingFlags.Instance | BindingFlags.Public);
addMethod?.Invoke(child, new object[] { });
foreach (var data in partBehaviourModule.DataModules.Values)
{
data.GetType().GetMethod("RebuildDataContext", BindingFlags.Instance | BindingFlags.NonPublic)
?.Invoke(data, new object[] { });
var rebuildMethod = data.GetType().GetMethod("RebuildDataContext", BindingFlags.Instance | BindingFlags.NonPublic) ?? data.GetType().GetMethod("RebuildDataContext", BindingFlags.Instance | BindingFlags.Public);
rebuildMethod?.Invoke(data, new object[] { });
}
core.data.serializedPartModules.Add(new SerializedPartModule(child,false));
core.data.serializedPartModules.Add(new SerializedPartModule(partBehaviourModule,false));
}
var json = IOProvider.ToJson(core);
File.WriteAllText($"{Application.dataPath}/{core.data.partName}.json", json);
Expand Down
130 changes: 128 additions & 2 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ GameObject:
- component: {fileID: 2045490031}
- component: {fileID: 2045490030}
- component: {fileID: 2045490029}
- component: {fileID: 2045490035}
m_Layer: 0
m_Name: TestPart
m_TagString: Untagged
Expand Down Expand Up @@ -1304,9 +1305,13 @@ MonoBehaviour:
ModuleData:
- Name: Data_Fairing
Data:
- Name: PartComponentModule_CompoundPart
- Name: PartComponentModule_DeployableControlSurface
ModuleData:
- Name: Data_CompoundPart
- Name: Data_LiftingSurface
Data:
- Name: Data_ControlSurface
Data:
- Name: Data_DeployableControlSurface
Data:
resourceSummary:
Consumes:
Expand Down Expand Up @@ -1339,3 +1344,124 @@ MonoBehaviour:
PickUpPointOffset: {x: 0, y: 0, z: 0}
PickupRotationPointOffset: {x: 0, y: 0, z: 0}
legacyModules:
--- !u!114 &2045490035
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2045490027}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 235333479, guid: 3046f413347669c40bed1fd7b4c64202, type: 3}
m_Name:
m_EditorClassIdentifier:
dataLiftingSurface:
omnidirectional: 1
liftCurve:
fCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
_minTime: 3.4028235e+38
_maxTime: -3.4028235e+38
liftMachCurve:
fCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
_minTime: 3.4028235e+38
_maxTime: -3.4028235e+38
dragCurve:
fCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
_minTime: 3.4028235e+38
_maxTime: -3.4028235e+38
dragMachCurve:
fCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
_minTime: 3.4028235e+38
_maxTime: -3.4028235e+38
liftingSurfaceCurve: Default
transformDir: 2
transformSign: 1
transformName:
nodeEnabled: 0
attachNodeName:
deflectionLiftCoeff: 1.5
perpendicularOnly: 0
useInternalDragModel: 1
CoPOffset: {x: 0, y: 0, z: 0}
baseTransform: {fileID: 0}
debugThis: 0
dataCtrlSurface:
IsCtrlSurfaceActive: 0
LiftingCtrlSurfaceArea: 0
CoPressureCtrlSurfaceOffset: {x: 0, y: 0, z: 0}
CtrlSurfacePivotOffset: {x: 0, y: 0, z: 0}
CtrlTransformDir: 2
CtrlTransformRotAxis: 0
CtrlTransformSign: -1
CtrlSurfacePivotTransformName: obj_ctrlSrf
CtrlSurfaceRange: 15
CtrlSurfaceArea: 0.5
UseExponentialSpeed: 0
ActuatorSpeedNormalScale: 30
MirrorDeploy: 0
MeshAreaLiftMultiplier: 0.25
DisableLiftingSurfaceForce: 0
ApplyLiftSurfaceForceAtBase: 0
ApplyLiftSurfaceForceAtPivotMidpoint: 0
_ctrlSurface: {fileID: 0}
_deflectionDirection: 1
_referenceXform: {fileID: 0}
animator: {fileID: 0}
dataDeployableControlSurface: {}

0 comments on commit 7cbbff5

Please sign in to comment.