1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using UnityEngine;
- using System.Collections;
- public class ManaAudio : Regist
- {
- #region 变量
- public Coroutine CoroTheme;
- public Coroutine CoroMiniGame;
- public AudioSource MusicMini;
- public AudioSource MusicTheme;
- #endregion
- private void Awake()
- {
- Transform tra = new GameObject("Audio").transform;
- ManaReso.Get("MusicMini", Folder.Object, true, tra, true);
- ManaReso.Get("MusicTheme", Folder.Object, true, tra, true);
- }
- public override void RegistValueA()
- {
- #region MusicMini
- Transform tra = MusicMini.transform;
- TweenAudio tween = tra.CreateTweenAudio(1, 2f, true, true, Curve.EaseOutQuad);
- tween.OnForwardStart += () =>
- {
- MusicMini.Play();
- CoroTheme = StartCoroutine(Loop(MusicMini));
- };
- tween.OnBackwardStart += () =>
- {
- StopCoroutine(CoroTheme);
- };
- #endregion
- #region MusicTheme
- tra = MusicTheme.transform;
- tween = tra.CreateTweenAudio(1, 2f, true, true, Curve.EaseOutQuad);
- tween.OnForwardStart += () =>
- {
- MusicTheme.Play();
- CoroTheme = StartCoroutine(Loop(MusicTheme));
- };
- tween.OnBackwardStart += () =>
- {
- StopCoroutine(CoroTheme);
- };
- #endregion
- ManaReso.Get("MusicTheme").TweenForAudio();
- }
- public override void RegistReference()
- {
- MusicMini = ManaReso.Get<AudioSource>("MusicMini");
- MusicTheme = ManaReso.Get<AudioSource>("MusicTheme");
- }
- private IEnumerator Loop(AudioSource audioSource)
- {
- while (true)
- {
- while (audioSource.isPlaying)
- {
- yield return null;
- }
- yield return new WaitForSeconds(3);
- audioSource.Play();
- }
- }
- }
|