Version: 2019.2
public bool GetData (float[] data, int offsetSamples);

Description

Заполняет массив с образцами данных из клипа.

The samples are floats ranging from -1.0f to 1.0f. The sample count is determined by the length of the float array. Use the offsetSamples parameter to start the read from a specific position in the clip. If the read length from the offset is longer than the clip length, the read will wrap around and read the remaining samples from the start of the clip.

Заметьте, что с компрессией аудио файлов, данные могут быть восстановлены только когда тип "Load Type" установлен в "Decompress On Load" в аудио импортере. Если это не так, то массив будет возвращен с нулями для всех значений.

using UnityEngine;

public class Example : MonoBehaviour { // Read all the samples from the clip, reducing their gain by half // as we go along.

void Start() { AudioSource audioSource = GetComponent<AudioSource>(); float[] samples = new float[audioSource.clip.samples * audioSource.clip.channels]; audioSource.clip.GetData(samples, 0);

for (int i = 0; i < samples.Length; ++i) { samples[i] = samples[i] * 0.5f; }

audioSource.clip.SetData(samples, 0); } }