private static LayeredAudio GetLayeredAudio(LocoAudioShunter locoAudio) { var engineTransform = locoAudio.transform.Find("Engine"); var coolingFanGO = engineTransform.Find("CoolingFan")?.gameObject; if (coolingFanGO == null) { coolingFanGO = new GameObject("CoolingFan"); coolingFanGO.transform.parent = engineTransform; coolingFanGO.transform.localPosition = Vector3.zero; coolingFanGO.transform.localRotation = Quaternion.identity; var source = coolingFanGO.AddComponent <AudioSource>(); source.loop = true; source.clip = FileAudio.Load("Ventilation Fan drone 2.mp3"); source.spatialBlend = 1f; source.pitch = 1f; var layer = new LayeredAudio.Layer() { name = "CoolingFan", volumeCurve = AnimationCurve.Linear(0, 0, 1, 2), inertia = 2f, inertialPitch = true, source = source, }; var layered = coolingFanGO.AddComponent <LayeredAudio>(); layered.layers = new LayeredAudio.Layer[] { layer }; layered.linearPitchLerp = true; layered.minPitch = 0f; } return(coolingFanGO.GetComponent <LayeredAudio>()); }
void Awake() { var audioAnchors = transform?.Find("Audio anchors"); var engineAudio = audioAnchors.transform?.Find("Engine"); var Engine_Layered = engineAudio?.Find("Engine_Layered(Clone)"); var Engine_Layered_Audio = Engine_Layered.GetComponent <LayeredAudio>(); var EngineFan_Layered = new GameObject(); EngineFan_Layered.name = "EngineFan_Layered"; EngineFan_Layered.transform.parent = engineAudio; EngineFan_Layered.transform.localPosition = Vector3.zero; EngineFan_Layered.transform.localRotation = Quaternion.identity; var train_engine_layer_fan = new GameObject(); train_engine_layer_fan.name = "train_engine_layer_fan"; train_engine_layer_fan.transform.parent = EngineFan_Layered.transform; train_engine_layer_fan.transform.localPosition = Vector3.zero; train_engine_layer_fan.transform.localRotation = Quaternion.identity; var audioSource = train_engine_layer_fan.AddComponent <AudioSource>(); audioSource.outputAudioMixerGroup = Engine_Layered_Audio.audioMixerGroup; audioSource.playOnAwake = true; audioSource.loop = true; audioSource.maxDistance = 300f; audioSource.clip = Main.fanAudioClip; audioSource.spatialBlend = 1f; audioSource.dopplerLevel = 0f; audioSource.spread = 10f; var audioLayer = new LayeredAudio.Layer(); audioLayer.name = "engine_fan"; audioLayer.volumeCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f); audioLayer.usePitchCurve = false; audioLayer.inertia = 0f; audioLayer.inertialPitch = false; audioLayer.source = audioSource; audioLayer.refVelo = 0f; audioLayer.startPitch = 0.5f; var layeredAudio = EngineFan_Layered.AddComponent <LayeredAudio>(); layeredAudio.audioMixerGroup = Engine_Layered_Audio.audioMixerGroup; layeredAudio.layers = new LayeredAudio.Layer[1]; layeredAudio.layers[0] = audioLayer; layeredAudio.RandomizeTime(); layeredAudio.Reset(); layeredAudio.Play(); layeredAudio.masterVolume = 0.6f; fanAudio = layeredAudio; controller = gameObject.GetComponent <LocoControllerShunter>(); }