void Start() { if (SoundMaterial == null || SoundMaterial.AudioSets.Count == 0) { return; } if (AutoCreateSources) { if (!ImpactAudio.isActiveAndEnabled) { ImpactAudio = getAudioCopy(ImpactAudio, gameObject); } baseImpactVol = ImpactAudio.volume; baseImpactPitch = ImpactAudio.pitch; audioContainersDic = new Dictionary <int, PhysSoundAudioContainer>(); AudioContainers = new List <PhysSoundAudioContainer>(); foreach (PhysSoundAudioSet audSet in SoundMaterial.AudioSets) { PhysSoundAudioContainer audCont = new PhysSoundAudioContainer(audSet.Key); audCont.SlideAudio = getAudioCopy(ImpactAudio, this.gameObject); audCont.Initialize(SoundMaterial.GetAudioSet(audCont.KeyIndex).Slide); audioContainersDic.Add(audCont.KeyIndex, audCont); AudioContainers.Add(audCont); } ImpactAudio.loop = false; } else { if (ImpactAudio) { ImpactAudio.loop = false; baseImpactVol = ImpactAudio.volume; baseImpactPitch = ImpactAudio.pitch; } if (AudioContainers.Count > 0) { audioContainersDic = new Dictionary <int, PhysSoundAudioContainer>(); foreach (PhysSoundAudioContainer audCont in AudioContainers) { if (!SoundMaterial.HasAudioSet(audCont.KeyIndex)) { Debug.LogError("PhysSound Object " + gameObject.name + " has an audio container for an invalid Material Type! Select this object in the hierarchy to update its audio container list."); continue; } audCont.Initialize(SoundMaterial.GetAudioSet(audCont.KeyIndex).Slide); audioContainersDic.Add(audCont.KeyIndex, audCont); } } } }
/// <summary> /// Initializes this Audio Container with the given AudioClip. Will do nothing if SlideAudio is not assigned. /// </summary> /// <param name="clip"></param> public void Initialize(PhysSoundMaterial m) { if (SlideAudio == null) { return; } _mat = m; SlideAudio.clip = _mat.GetAudioSet(KeyIndex).Slide; _baseVol = SlideAudio.volume; _basePitch = SlideAudio.pitch; _basePitchRand = _basePitch; SlideAudio.loop = true; SlideAudio.volume = 0; }