public void Initialize(AudioSourceSettings settings, AudioItemManager itemManager, AudioSource audioSource, AudioSpatializer spatializer, IAudioItem parent) { base.Initialize(settings.Identifier, itemManager, spatializer, parent); // General Setup originalSettings = settings; this.settings = PrefabPoolManager.Create(settings); source = audioSource; source.transform.parent = itemManager.AudioManager.Reference.transform.parent; base.spatializer.AddSource(source.transform); // Setup the AudioSource source.Stop(); source.clip = this.settings.Clip; source.name = settings.Name; source.outputAudioMixerGroup = this.settings.Output; source.loop = this.settings.Loop; source.spatialBlend = base.spatializer.SpatializeMode == AudioSpatializer.SpatializeModes.None ? 0f : source.spatialBlend; InitializeModifiers(originalSettings); for (int i = 0; i < originalSettings.Options.Count; i++) { ApplyOption(originalSettings.Options[i], false); } if (this.settings.MaxInstances > 0) { itemManager.TrimInstances(this, this.settings.MaxInstances); } }
public override void OnEnable() { base.OnEnable(); sourceSettings = target as AudioSourceSettings; clipProperty = serializedObject.FindProperty("Clip"); InitializeTextures(); }
public void Copy(AudioSourceItem reference) { base.Copy(reference); originalSettings = reference.originalSettings; settings = reference.settings; source = reference.source; deltaTime = reference.deltaTime; lastTime = reference.lastTime; }
void ShowWaves() { AudioClip clip = clipProperty.GetValue <AudioClip>(); string playRangeStartSeconds = clip == null ? "" : "(" + (sourceSettings.PlayRangeStart * clip.length).Round(0.01f) + "s)"; string playRangeEndSeconds = clip == null ? "" : "(" + (sourceSettings.PlayRangeEnd * clip.length).Round(0.01f) + "s)"; string curvesLabel = string.Format("Start: {0} {2} | End: {1} {3}", sourceSettings.PlayRangeStart.Round(0.01f), sourceSettings.PlayRangeEnd.Round(0.01f), playRangeStartSeconds, playRangeEndSeconds); EditorGUILayout.LabelField(curvesLabel, GUILayout.Height(22f)); AudioManagerEditor.ShowPreviewButton(EditorGUI.IndentedRect(GUILayoutUtility.GetLastRect()), sourceSettings); EditorGUI.BeginChangeCheck(); Rect rect = EditorGUI.IndentedRect(GUILayoutUtility.GetLastRect()); EditorGUI.MinMaxSlider(new Rect(rect.x - 9f, rect.y + 12f, rect.width + 10f, rect.height), ref sourceSettings.PlayRangeStart, ref sourceSettings.PlayRangeEnd, 0f, 1f); if (EditorGUI.EndChangeCheck()) { for (int i = 0; i < targets.Length; i++) { AudioSourceSettings settings = (AudioSourceSettings)targets[i]; settings.PlayRangeStart = float.IsNaN(sourceSettings.PlayRangeStart) ? 0f : Mathf.Clamp(sourceSettings.PlayRangeStart, 0f, settings.PlayRangeEnd); settings.PlayRangeEnd = float.IsNaN(sourceSettings.PlayRangeEnd) ? 1f : Mathf.Clamp(sourceSettings.PlayRangeEnd, settings.PlayRangeStart, 1f); } serializedObject.Update(); ClampFades(); } if (clip == null || clip.channels == 1) { ShowWave(textureLeft, 40f); } else { ShowWave(textureLeft, 20f); ShowWave(textureRight, 20f); } }