Exemple #1
0
 public void Play(SFXData data)
 {
     this.data = data;
     _duration = 9999f;
     if (data.ReferencedClip.Asset != null)
     {
         OnLoaded(data.ReferencedClip.Asset as AudioClip);
     }
     else if (data.ReferencedClip.OperationHandle.IsValid())
     {
         if (data.ReferencedClip.OperationHandle.IsDone)
         {
             OnLoaded(data.ReferencedClip.OperationHandle.Result as AudioClip);
         }
         else
         {
             data.ReferencedClip.OperationHandle.Completed += h => OnLoaded(h.Result as AudioClip);
         }
     }
     else
     {
         try
         {
             data.ReferencedClip.LoadAssetAsync <AudioClip>().Completed += h => OnLoaded(h.Result);
         }
         catch (System.Exception) { }
     }
 }
Exemple #2
0
 public void Play(SFXData data, Transform parent)
 {
     Play(data);
     _source.spatialBlend = 1f;
     _transform.position  = parent.position;
     _toFollow            = parent;
 }
Exemple #3
0
 void ReleasePlayingClip(SFXData clip)
 {
     if (clip != null && _loadedClips.ContainsKey(clip))
     {
         _loadedClips[clip] = Mathf.Max(0, _loadedClips[clip]);
     }
 }
Exemple #4
0
 public void PlaySFX(SFXData SFXType)
 {
     if (SFXSource != null)
     {
         SFXSource.mute = !EssentialData.Instance.LoadSettingSFX();
         SFXSource.PlayOneShot(SFXClip[(int)SFXType - 1]);
     }
 }
Exemple #5
0
 public void Reset()
 {
     data = null;
     _source.Stop();
     _looping  = false;
     _elapsed  = 0f;
     _duration = 0f;
     _toFollow = null;
     _transform.localPosition = Vector3.zero;
     gameObject.SetActive(false);
     Id = -1;
 }
Exemple #6
0
        public void Play(string name)
        {
            if (_playingClip != null && string.Equals(name, _playingClip.ClipName, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }
            if (_playingClip != null)
            {
                _source.Stop();
                _playingClip.ReferencedClip.ReleaseAsset();
            }

            if (string.IsNullOrEmpty(name))
            {
                _playingClip = null;
                return;
            }
            var clip = _clipStorer.GetClipByName(name);

            _playingClip = clip;
            clip.ReferencedClip.LoadAssetAsync <AudioClip>().Completed += h => OnClipLoaded(h.Result);
        }
Exemple #7
0
 public void Play(SFXData data, Vector3 position)
 {
     Play(data);
     _source.spatialBlend = 1f;
     _transform.position  = position;
 }
Exemple #8
0
    private void Awake()
    {
        audioSource = gameObject.AddComponent <AudioSource>();

        settings = Resources.Load <SFXData>("SFXSettings");
    }