/// <summary>
            /// Creates a new clip from an AudioClip and adds it to the track
            /// </summary>
            public BlendClip AddClip(AudioClip clip, float time)
            {
                BlendClip c = new BlendClip(clip, time, this);

                clips.Add(c);
                return(c);
            }
 /// <summary>
 /// Removes a clip from the track without destroying it. Used when moving clips to other tracks
 /// </summary>
 /// <param name="index"></param>
 public void UnlinkClip(BlendClip clip)
 {
     for (int i = 0; i < clips.Count; i++)
     {
         if (clips[i] == clip)
         {
             UnlinkClip(i);
             break;
         }
     }
 }
 /// <summary>
 /// Removes a clip by reference permanently
 /// </summary>
 /// <param name="clip"></param>
 public void RemoveClip(BlendClip clip)
 {
     for (int i = 0; i < clips.Count; i++)
     {
         if (clips[i] == clip)
         {
             RemoveClip(i);
             break;
         }
     }
 }
            /// <summary>
            /// Removes a clip by index permanently
            /// </summary>
            /// <param name="index"></param>
            public void RemoveClip(int index)
            {
                if (index < 0 || index >= clips.Count)
                {
                    throw new UnityException("Clip " + index + " does not exist");
                }
#if UNITY_EDITOR
                UnityEditor.Undo.RecordObject(sequence.blender, "Delete Clips");
#endif
                BlendClip clip = clips[index];
                clips.RemoveAt(index);
#if UNITY_EDITOR
                clip.Destroy();
#endif
            }
 /// <summary>
 /// Adds an existing clip to this track. If the clip belongs to another track it will be removed from the other track
 /// </summary>
 /// <param name="clip"></param>
 public void AddClip(BlendClip clip)
 {
     for (int i = 0; i < clips.Count; i++)
     {
         if (clips[i] == clip)
         {
             return;
         }
     }
     if (clip.track != null)
     {
         clip.track.RemoveClip(clip);
     }
     clip.Init(this, false, true);
     clips.Add(clip);
 }
            void HandleOneshot(BlendClip clip, float time, float lastTime)
            {
                float anchor = Mathf.Lerp(clip.start, clip.end, clip.oneshotAnchor);

                if (!clip.isPlaying)
                {
                    if ((lastTime < anchor && time >= anchor) || (lastTime > anchor && time <= anchor))
                    {
                        clip.Play(0f);
                    }
                }
                else
                {
                    clip.HandleVolume(sequence.fade * sequence.volume * sequence.blender.masterVolume * panBlend, clip.source.time / clip.audioClip.length * volume);
                    clip.HandlePitch(sequence.pitch * sequence.blender.masterPitch, clip.source.time / clip.audioClip.length);
                }
            }
            void HandleClip(BlendClip clip, float time)
            {
                float percent = 0f;

                if (clip.Evaluate(time, out percent))
                {
                    if (!clip.isPlaying)
                    {
                        clip.Play(percent);
                    }
                    clip.HandleVolume(sequence.fade * sequence.volume * sequence.blender.masterVolume * panBlend * volume, percent);
                    clip.HandlePitch(sequence.pitch * sequence.blender.masterPitch, percent);
                }
                else
                {
                    if (clip.isPlaying)
                    {
                        clip.Pause();
                    }
                }
            }
Beispiel #8
0
                public BlendClip Copy()
                {
                    BlendClip newClip = new BlendClip(_track);

                    newClip.audioClip          = audioClip;
                    newClip.start              = start;
                    newClip.duration           = _duration;
                    newClip.fadeIn             = _fadeIn;
                    newClip.fadeOut            = _fadeOut;
                    newClip.playType           = _playType;
                    newClip.startOffset        = startOffset;
                    newClip.minRandomStartTime = minRandomStartTime;
                    newClip.maxRandomStartTime = maxRandomStartTime;
                    newClip.startTimeMode      = startTimeMode;
                    newClip.volume             = volume;
                    newClip.pitch              = pitch;
                    newClip.usePitchEnvelope   = usePitchEnvelope;
                    newClip.useVolumeEnvelope  = useVolumeEnvelope;

                    if (fadeInCurve != null)
                    {
                        newClip.fadeInCurve = DuplicateUtility.DuplicateCurve(fadeInCurve);
                    }
                    if (fadeOutCurve != null)
                    {
                        newClip.fadeOutCurve = DuplicateUtility.DuplicateCurve(fadeOutCurve);
                    }
                    if (pitchEnvelope != null)
                    {
                        newClip.pitchEnvelope = DuplicateUtility.DuplicateCurve(pitchEnvelope);
                    }
                    if (volumeEnvelope != null)
                    {
                        newClip.volumeEnvelope = DuplicateUtility.DuplicateCurve(volumeEnvelope);
                    }
                    return(newClip);
                }