11using System . Collections ;
22using System . Collections . Generic ;
3+ using System . Runtime . InteropServices ;
34using RocketSoundEnhancement . AudioFilters ;
45using RocketSoundEnhancement . Unity ;
56using UnityEngine ;
@@ -17,7 +18,6 @@ public class RSE_Module : PartModule
1718
1819 public GameObject AudioParent { get ; protected set ; }
1920
20- public ConfigNode PartConfigNode ;
2121 public bool PrepareSoundLayers = true ;
2222 public bool Initialized ;
2323 public bool GamePaused ;
@@ -54,49 +54,8 @@ public override void OnStart(StartState state)
5454 string partParentName = part . name + "_" + this . moduleName ;
5555 AudioParent = AudioUtility . CreateAudioParent ( part , partParentName ) ;
5656
57- if ( ! float . TryParse ( PartConfigNode . GetValue ( "volume" ) , out Volume ) ) Volume = 1 ;
58- if ( ! float . TryParse ( PartConfigNode . GetValue ( "DopplerFactor" ) , out DopplerFactor ) ) DopplerFactor = 0.5f ;
59-
60- if ( PartConfigNode . HasNode ( "AIRSIMULATION" ) )
61- {
62- var node = PartConfigNode . GetNode ( "AIRSIMULATION" ) ;
63-
64- if ( node . HasValue ( "EnableCombFilter" ) ) bool . TryParse ( node . GetValue ( "EnableCombFilter" ) , out EnableCombFilter ) ;
65- if ( node . HasValue ( "EnableLowpassFilter" ) ) bool . TryParse ( node . GetValue ( "EnableLowpassFilter" ) , out EnableLowpassFilter ) ;
66- if ( node . HasValue ( "EnableDistortionFilter" ) ) bool . TryParse ( node . GetValue ( "EnableDistortionFilter" ) , out EnableDistortionFilter ) ;
67-
68- if ( node . HasValue ( "UpdateMode" ) ) node . TryGetEnum ( "UpdateMode" , ref AirSimUpdateMode , AirSimulationUpdate . Full ) ;
69-
70- if ( node . HasValue ( "FarLowpass" ) ) FarLowpass = float . Parse ( node . GetValue ( "FarLowpass" ) ) ;
71- if ( node . HasValue ( "MaxCombDelay" ) ) MaxCombDelay = float . Parse ( node . GetValue ( "MaxCombDelay" ) ) ;
72- if ( node . HasValue ( "MaxCombMix" ) ) MaxCombMix = float . Parse ( node . GetValue ( "MaxCombMix" ) ) ;
73- if ( node . HasValue ( "MaxDistortion" ) ) MaxDistortion = float . Parse ( node . GetValue ( "MaxDistortion" ) ) ;
74- if ( node . HasValue ( "AngleHighpass" ) ) AngleHighpass = float . Parse ( node . GetValue ( "AngleHighpass" ) ) ;
75- }
76-
77- UseAirSimulation = ! ( ! EnableLowpassFilter && ! EnableCombFilter && ! EnableDistortionFilter ) ;
78-
7957 if ( PrepareSoundLayers )
8058 {
81- foreach ( var node in PartConfigNode . GetNodes ( ) )
82- {
83- var soundLayers = AudioUtility . CreateSoundLayerGroup ( node . GetNodes ( "SOUNDLAYER" ) ) ;
84- if ( soundLayers . Count == 0 ) continue ;
85-
86- var groupName = node . name ;
87-
88- if ( node . name == "SOUNDLAYERGROUP" )
89- {
90- groupName = node . GetValue ( "name" ) ;
91- }
92-
93- if ( SoundLayerGroups . ContainsKey ( groupName ) ) { SoundLayerGroups [ groupName ] . AddRange ( soundLayers ) ; continue ; }
94-
95- SoundLayerGroups . Add ( groupName , soundLayers ) ;
96- }
97-
98- SoundLayers = AudioUtility . CreateSoundLayerGroup ( PartConfigNode . GetNodes ( "SOUNDLAYER" ) ) ;
99-
10059 if ( SoundLayerGroups . Count > 0 )
10160 {
10261 foreach ( var soundLayerGroup in SoundLayerGroups )
@@ -262,7 +221,7 @@ public void PlaySoundLayer(SoundLayer soundLayer, float control, float volume, b
262221
263222 if ( source . isPlaying && soundLayer . loop )
264223 source . volume = 0 ;
265-
224+
266225 return ;
267226 }
268227
@@ -342,15 +301,58 @@ public override void OnLoad(ConfigNode node)
342301 {
343302 base . OnLoad ( node ) ;
344303
345- if ( part . partInfo is null )
304+ if ( part ? . partInfo ? . partPrefab != null )
305+ {
306+ var prefab = part . partInfo . partPrefab . FindModuleImplementing < RSE_Module > ( ) ;
307+
308+ SoundLayerGroups = prefab . SoundLayerGroups ;
309+ SoundLayers = prefab . SoundLayers ;
310+ return ;
311+ }
312+
313+ // Do the actual parsing during part compilation.
314+
315+ node . TryGetValue ( "volume" , ref Volume ) ;
316+ node . TryGetValue ( "DopplerFactor" , ref DopplerFactor ) ;
317+
318+ ConfigNode sim = null ;
319+ if ( node . TryGetNode ( "AIRSIMULATION" , ref sim ) )
346320 {
347- PartConfigNode = node ;
321+ sim . TryGetValue ( "EnableCombFilter" , ref EnableCombFilter ) ;
322+ sim . TryGetValue ( "EnableLowpassFilter" , ref EnableLowpassFilter ) ;
323+ sim . TryGetValue ( "EnableDistortionFilter" , ref EnableDistortionFilter ) ;
324+
325+ sim . TryGetEnum ( "UpdateMode" , ref AirSimUpdateMode , AirSimulationUpdate . Full ) ;
326+
327+ sim . TryGetValue ( "FarLowpass" , ref FarLowpass ) ;
328+ sim . TryGetValue ( "MaxCombDelay" , ref MaxCombDelay ) ;
329+ sim . TryGetValue ( "MaxCombMix" , ref MaxCombMix ) ;
330+ sim . TryGetValue ( "MaxDistortion" , ref MaxDistortion ) ;
331+ sim . TryGetValue ( "AngleHighpass" , ref AngleHighpass ) ;
348332 }
349- else
333+
334+ UseAirSimulation = ! ( ! EnableLowpassFilter && ! EnableCombFilter && ! EnableDistortionFilter ) ;
335+
336+ if ( PrepareSoundLayers )
350337 {
351- PartConfigNode = part . partInfo . partPrefab
352- . FindModuleImplementing < RSE_Module > ( )
353- . PartConfigNode ;
338+ foreach ( var lnode in node . GetNodes ( ) )
339+ {
340+ var soundLayers = AudioUtility . CreateSoundLayerGroup ( lnode . GetNodes ( "SOUNDLAYER" ) ) ;
341+ if ( soundLayers . Count == 0 ) continue ;
342+
343+ var groupName = lnode . name ;
344+
345+ if ( lnode . name == "SOUNDLAYERGROUP" )
346+ {
347+ groupName = lnode . GetValue ( "name" ) ;
348+ }
349+
350+ if ( SoundLayerGroups . ContainsKey ( groupName ) ) { SoundLayerGroups [ groupName ] . AddRange ( soundLayers ) ; continue ; }
351+
352+ SoundLayerGroups . Add ( groupName , soundLayers ) ;
353+ }
354+
355+ SoundLayers = AudioUtility . CreateSoundLayerGroup ( node . GetNodes ( "SOUNDLAYER" ) ) ;
354356 }
355357 }
356358 }
0 commit comments