private void CheckSFXLengthAndAllocations <T>(AudioEventDictionary <T> list, SFX_Types sfxType) { if (Enum.GetValues(typeof(T)).Length != list.Count) { traceWarn("WARNING: Mismatched Length for Audio Clips for enum: " + typeof(T)); } list.sourceList = new List <AudioSource>(); list.sfxType = sfxType; if (!sourceAllocations.ContainsKey(sfxType)) { traceWarn("Missing Audiosource allocation-count for SFX type: " + sfxType); return; } int numSources = sourceAllocations[sfxType]; for (int s = numSources; --s >= 0;) { AudioSource dup = _audioSourcesGO.AddClone(source); dup.gameObject.name = dup.gameObject.name.Replace("(Template)", ""); list.sourceList.Add(dup); } }
private AudioEventDictionary <T> ResolveSFXList <T>(T sfxEnum) { AudioEventDictionary <T> list = null; if (sfxEnum is SFX_UI) { list = (AudioEventDictionary <T>)(object) UIEventSFXList; } else if (sfxEnum is SFX_Music) { list = (AudioEventDictionary <T>)(object) MusicEventSFXList; } else if (sfxEnum is SFX_Attacks) { list = (AudioEventDictionary <T>)(object) AttacksEventSFXList; } else if (sfxEnum is SFX_Defenses) { list = (AudioEventDictionary <T>)(object) DefensesEventSFXList; } if (!list.ContainsKey(sfxEnum)) { traceError("Cannot play sound because it's missing / not implemented: " + sfxEnum); return(null); } if (list[sfxEnum] == null) { traceError("Missing SFX at enum: " + sfxEnum); return(null); } return(list); }
private bool PlayedRecently <T>(AudioEventDictionary <T> list, T sfxEnum) { float timeNow = Time.time; var lastUsed = list._lastUsed; if (lastUsed.ContainsKey(sfxEnum)) { float timeDiff = timeNow - lastUsed[sfxEnum]; if (timeDiff < timeForSFXConflicts) { return(true); } } lastUsed[sfxEnum] = timeNow; return(false); }