Example #1
0
        protected override void OnInitialise(bool inPreviewMode = false)
        {
            AudioSource component = base.gameObject.GetComponent <AudioSource>();

            if ((bool)component)
            {
                Debug.LogWarning("Fabric: Adding an AudioSource and AudioComponent [" + base.name + "] in the same gameObject will impact performance, move AudioSource in a new gameObject underneath");
            }
            int sampleFileIndexByName = SampleManager.Instance.GetSampleFileIndexByName(sampleFileName);

            if (sampleFileIndexByName >= 0 && (sampleFileIndexByName != _prevIndex || sampleFileInstance == null))
            {
                SampleFile sampleFileByIndex = SampleManager.Instance.GetSampleFileByIndex(sampleFileIndexByName);
                if (sampleFileByIndex != null)
                {
                    sampleFileInstance = sampleFileByIndex.GetInstance();
                    if (sampleFileInstance != null)
                    {
                        sampleFileInstance._start = _leftLoopMarker;
                        sampleFileInstance._end   = _rightLoopMarker;
                        base.AudioClip            = AudioClip.Create(sampleFileName + " (Custom)", _rightLoopMarker, sampleFileByIndex._channels, (int)sampleFileByIndex._sampleRate, stream: true, OnAudioRead);
                        sampleFileInstance._loop  = base.Loop;
                    }
                }
                _prevIndex = sampleFileIndexByName;
            }
            base.OnInitialise(inPreviewMode);
        }
Example #2
0
 public void NotifySampleFileRemoved(SampleFile sampleFile)
 {
     if (sampleFileInstance != null && sampleFileInstance._sampleFile == sampleFile)
     {
         sampleFileInstance = null;
         sampleFileName     = "";
     }
 }