NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/Audio/AudioCri.cs

482 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// using CriWare;
// using PhxhSDK;
// using UnityEngine;
//
// public class AudioCri: AudioBase
// {
// public static float GlobalVolume = 1f;
// public static float GlobalMusicVolume = 1f;
// public static float GlobalSoundVolume = 1f;
// public static float GlobalSpeakVolume = 1f;
//
// private GameObject _posGo;
// private CriAtomSource _criAtomSource;
// private bool _isSpeak;
// private bool _isStory;
// private static long _curPlayID;
// private long _playID = -1; //播放ID越小越早
// public long PlayID => _playID;
//
// public CriAtomExPlayback CriAtomExPlayback;
// public bool IsSpeak => _isSpeak;
// public bool IsStory => _isStory;
//
// private float _playPassTime = 0f;
// private float _stopPassTime = 0f;
// private float _fadeValue = 1f;
// private float _fadeInTime = 4f;
// private float _fadeOutTime = 4f;
// private bool _isInFadeIn; //Fade过程中
// private bool _isInFadeOut; //Fade过程中
// private bool _isFadeIn;
// private bool _isFadeOut;
//
// private float _clipVolume = 1f;
//
// public enum VolumeType
// {
// Music,
// Sound,
// Speak
// }
//
// #region Construct
//
// public AudioCri(AudioType audioType, GameObject rootGo, GameObject posGo, AudioInfo audioInfo,
// bool loop = false, bool is3D = false)
// {
// this.audioType = audioType;
// _rootGo = rootGo;
// _posGo = posGo;
// _criAtomSource = _GetSource();
// _criAtomSource.volume = GlobalVolume;
// targetVolume = 1f;
// _isSpeak = audioInfo.isSpeak;
// }
//
// private CriAtomSource _GetSource()
// {
// var source = _rootGo.GetComponent<CriAtomSource>();
// if (!source)
// {
// source = _rootGo.AddComponent<CriAtomSource>();
// }
//
// return source;
// }
//
// private void SetSourceData(AudioInfo audioInfo)
// {
//
// }
// #endregion
//
// #region Inherit
//
// public override void Update()
// {
//
// }
// public override void Update(float dt)
// {
// if (!_criAtomSource)
// {
// return;
// }
//
// if (_isFadeIn || _isFadeOut)
// {
// _UpdateFade(dt);
// return;
// }
//
// _fadeValue = 1f;
// //SetVolume
// if (playState == PlayState.Playing || _criAtomSource.status == CriAtomSourceBase.Status.Playing)
// {
// //渐入渐出
// //_UpdateFadeValue(dt);
//
// switch (audioType)
// {
// case (AudioType.Music):
// {
// _SetMusicVolume();
// break;
// }
//
// case (AudioType.Sound):
// {
// if (_isSpeak)
// {
// _SetSpeakVolume();
// }
// else
// {
// _SetSoundVolume();
// }
// break;
// }
//
// default:
// break;
// }
// }
//
// if (_posGo && playState == PlayState.Playing)
// {
// _rootGo.transform.position = _posGo.transform.position;
// }
//
// //Update Play Status
// if (_criAtomSource.status == CriAtomSourceBase.Status.PlayEnd)
// {
// Stop();
// }
//
// if (_criAtomSource.status == CriAtomSourceBase.Status.Stop)
// {
// Stop();
// }
// }
//
// private void _UpdateFade(float dt)
// {
// if (playState == PlayState.Playing || _criAtomSource.status == CriAtomSourceBase.Status.Playing)
// {
// //渐入渐出
// _UpdateFadeValue(dt);
//
// switch (audioType)
// {
// case (AudioType.Music):
// {
// _SetMusicVolume();
// break;
// }
//
// case (AudioType.Sound):
// {
// if (_isSpeak)
// {
// _SetSpeakVolume();
// }
// else
// {
// _SetSoundVolume();
// }
// break;
// }
//
// default:
// break;
// }
// }
//
// if (_posGo && playState == PlayState.Playing)
// {
// _rootGo.transform.position = _posGo.transform.position;
// }
//
// //Update Play Status
// if (_criAtomSource.status == CriAtomSourceBase.Status.PlayEnd)
// {
// if (_stopPassTime > _fadeOutTime)
// {
// Stop();
// }
// }
//
// if (_criAtomSource.status == CriAtomSourceBase.Status.Stop)
// {
// if (_stopPassTime > _fadeOutTime)
// {
// Stop();
// }
// }
// }
//
// public override void Pause()
// {
// _criAtomSource.Pause(true);
// playState = PlayState.Paused;
// }
//
// public override void Resume()
// {
// _criAtomSource.Pause(false);
// playState = PlayState.Playing;
// }
//
// public override void Play(float volume = 1f)
// {
// playState = PlayState.Playing;
// _isFadeOut = false;
// //_criAtomSource.player?.DetachFader();
// targetVolume = 1f;
// _criAtomSource.Play();
// _playID = _GenPlayID();
// AudioManager.Instance.AudioMgrObj.Add2Playing(audioType, audioID, _isSpeak);
// }
//
// public void PlayWithFade(float volume = 1f)
// {
// playState = PlayState.Playing;
// //_criAtomSource.player?.AttachFader();
// _criAtomSource.Play();
// _playID = _GenPlayID();
// AudioManager.Instance.AudioMgrObj.RemovePlaying(audioType, audioID);
// }
// public void Stop()
// {
// _isFadeOut = false;
// _isFadeIn = false;
// _isInFadeIn = false;
// _isInFadeOut = false;
// _playPassTime = 0;
// _stopPassTime = 0;
// if (_criAtomSource.status == CriAtomSourceBase.Status.Stop && playState == PlayState.Stopped)
// {
// return;
// }
// _criAtomSource.Stop();
// //_criAtomSource.player?.DetachFader();
// base.Stop();
// AudioManager.Instance.AudioMgrObj.RemovePlaying(audioType, audioID);
// }
//
// public void StopWithFade(float fadeOutTime = 1f)
// {
// if (_isInFadeOut)
// return;
// _isFadeOut = true;
// _playPassTime = 0f;
// _isInFadeOut = true;
// _stopPassTime = 0f;
// _fadeOutTime = fadeOutTime;
// //AudioManager.Instance.AudioMgrObj.RemovePlaying(audioID);
// }
//
// #endregion
//
// #region Utils
//
// private long _GenPlayID()
// {
// return ++_curPlayID;
// }
// private void _SetMusicVolume()
// {
// _criAtomSource.volume = _fadeValue * GlobalMusicVolume * GlobalVolume * targetVolume;
// }
//
// private void _SetSoundVolume()
// {
// _criAtomSource.volume = _fadeValue * GlobalSoundVolume * GlobalVolume * targetVolume;
// }
//
// private void _SetSpeakVolume()
// {
// _criAtomSource.volume = _fadeValue * GlobalSpeakVolume * GlobalVolume * targetVolume;
// }
//
// private void _SetIs3D(bool is3D)
// {
// _criAtomSource.use3dPositioning = is3D;
// }
//
// private void _UpdateFadeValue(float dt)
// {
// if (_playPassTime > _fadeInTime)
// {
// _isInFadeIn = false;
// }
//
// if (_isFadeOut)
// {
// if(_isFadeIn)
// {
// targetVolume = _fadeValue;
// _isFadeIn = false;
// }
// }
//
// if (_isFadeIn)
// {
// if (_playPassTime < _fadeInTime)
// {
// _isInFadeIn = true;
// }
// else
// {
// _isInFadeIn = false;
// }
// }
//
// if (_isFadeOut)
// {
// if (_isInFadeOut)
// {
// _stopPassTime += dt;
// }
// }
// _playPassTime += dt;
//
// _SetCurFadeValue();
// }
// private void _SetCurFadeValue()
// {
// if (!_isInFadeIn && !_isInFadeOut)
// {
// _fadeValue = 1f;
// return;
// }
//
// if (_isInFadeOut)
// {
// _fadeValue = (1 - _stopPassTime / _fadeInTime);
// if (_fadeValue < 0)
// {
// _fadeValue = 0;
// Stop();
// }
// return;
// }
//
// if (_isInFadeIn && _playPassTime < _fadeInTime)
// {
// _fadeValue = _playPassTime / _fadeInTime;
// if (_fadeValue > 1)
// _fadeValue = 1;
// }
//
// //_fadeValue = 1f;
// }
// #endregion
//
// #region API
//
// public void Play(string cueName, AudioInfo audioInfo, bool isLoop = false)
// {
// _playPassTime = 0f;
// targetVolume = 1f;
// _isFadeOut = false;
// _isFadeIn = false;
// playState = PlayState.Playing;
// _playID = _GenPlayID();
// AudioManager.Instance.AudioMgrObj.Add2Playing(audioType, audioID, _isSpeak);
// }
//
// public void Play(string cueSheet, string cueName)
// {
// _criAtomSource.cueSheet = cueSheet;
// _criAtomSource.cueName = cueName;
//
// _playPassTime = 0f;
// _stopPassTime = 0f;
// _isFadeOut = false;
// _isFadeIn = false;
// targetVolume = 1f;
//
// //_criAtomSource.player?.DetachFader();
// CriAtomExPlayback = _criAtomSource.Play();
// playState = PlayState.Playing;
// _playID = _GenPlayID();
// AudioManager.Instance.AudioMgrObj.Add2Playing(audioType, audioID, _isSpeak);
// }
//
// public void PlayWithFade(string cueSheet, string cueName, float fadeInTime = 4f, float fadeOutTime = 4f)
// {
// _criAtomSource.cueSheet = cueSheet;
// _criAtomSource.cueName = cueName;
//
// _playPassTime = 0f;
// _stopPassTime = 0f;
// _isFadeOut = false;
// _isFadeIn = true;
// SetVolume(0);
// _criAtomSource.volume = 0f;
// _fadeInTime = fadeInTime;
// _fadeOutTime = fadeOutTime;
//
// //_criAtomSource.player?.AttachFader();
// CriAtomExPlayback = _criAtomSource.Play();
// playState = PlayState.Playing;
// _playID = _GenPlayID();
// AudioManager.Instance.AudioMgrObj.Add2Playing(audioType, audioID, _isSpeak);
// }
//
// public void SetIs3D(bool is3D = false)
// {
// _SetIs3D(is3D);
// }
//
// public void SetPosObj(GameObject go = null)
// {
// if (go)
// {
// _posGo = go;
// if (_rootGo)
// {
// _rootGo.transform.position = _posGo.transform.position;
// _SetIs3D(true);
// }
//
// return;
// }
//
// _posGo = null;
// _SetIs3D(false);
// }
//
//
// public void SetPos(Vector3 position)
// {
// _rootGo.transform.position = position;
// }
//
// public void SetIsLoop(bool isLoop)
// {
// loop = isLoop;
// _criAtomSource.loop = isLoop;
// //DebugUtil.LogError($"audioID:{audioID}, , name:{_criAtomSource.cueName}, isLoop:{isLoop}");
// }
//
// public void SetIsSpeak(bool isSpeak)
// {
// _isSpeak = isSpeak;
// }
//
// public void SetIsStory(bool isStory)
// {
// _isStory = isStory;
// }
// public void SetIsFadeIn(bool isFadeIn)
// {
// _isFadeIn = isFadeIn;
// }
//
// public string GetCueSheetName()
// {
// if (_criAtomSource)
// {
// return _criAtomSource.cueSheet;
// }
// return "";
// }
//
// // public long GetCurPlayLength()
// // {
// // var cueName = _criAtomSource.cueName;
// // var cueSheet = _criAtomSource.cueSheet;
// // var acb = AudioManager.Instance.AudioMgrObj.CriAtom.GetCueSheetInternal(cueSheet).acb;
// // if (acb.GetCueInfo(cueName, out var cueInfo))
// // {
// // var length = cueInfo.length / 1000;
// // return length;
// // }
// //
// // return -1;
// // }
// #endregion
// }