public void SetSource(AudioSource wholeSource, float offsetTime, MusicSectionDefinition definition) { this.OffsetTime = offsetTime; var samples = Mathf.FloorToInt(wholeSource.clip.frequency * definition.SecondsInSection); var offsetSamples = Mathf.FloorToInt(wholeSource.clip.frequency * offsetTime); var sectionClip = AudioClip.Create(definition.Name + "_Clip", samples, wholeSource.clip.channels, wholeSource.clip.frequency, false); var sectionData = new float[samples * wholeSource.clip.channels]; wholeSource.clip.GetData(sectionData, offsetSamples); sectionClip.SetData(sectionData, 0); sectionSource.clip = sectionClip; sectionSource.playOnAwake = false; sectionSource.loop = (definition.Transition == MusicSectionDefinition.TransitionType.Loop); sectionSource.volume = wholeSource.volume; this.transform.SetParent(wholeSource.transform); this.sectionDefinition = definition; }