211 lines
4.2 KiB
C#
211 lines
4.2 KiB
C#
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 int _playID;
|
|
|
|
public CriAtomExPlayback CriAtomExPlayback;
|
|
|
|
#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;
|
|
_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()
|
|
{
|
|
if (!_criAtomSource)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//SetVolume
|
|
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();
|
|
}
|
|
}
|
|
|
|
public override void Pause()
|
|
{
|
|
_criAtomSource.Pause(true);
|
|
}
|
|
|
|
public override void Resume()
|
|
{
|
|
_criAtomSource.Pause(false);
|
|
}
|
|
|
|
public override void Play(float volume)
|
|
{
|
|
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
_criAtomSource.Stop();
|
|
base.Stop();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Utils
|
|
|
|
private void _SetMusicVolume()
|
|
{
|
|
_criAtomSource.volume = GlobalMusicVolume * GlobalVolume;
|
|
}
|
|
|
|
private void _SetSoundVolume()
|
|
{
|
|
_criAtomSource.volume = GlobalSoundVolume * GlobalVolume;
|
|
}
|
|
|
|
private void _SetSpeakVolume()
|
|
{
|
|
_criAtomSource.volume = GlobalSpeakVolume * GlobalVolume;
|
|
}
|
|
|
|
private void _SetIs3D(bool is3D)
|
|
{
|
|
_criAtomSource.use3dPositioning = is3D;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region API
|
|
|
|
public void Play(string cueName, AudioInfo audioInfo, bool isLoop = false)
|
|
{
|
|
|
|
}
|
|
|
|
public void Play(string cueSheet, string cueName)
|
|
{
|
|
_criAtomSource.cueSheet = cueSheet;
|
|
_criAtomSource.cueName = cueName;
|
|
CriAtomExPlayback = _criAtomSource.Play();
|
|
}
|
|
|
|
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)
|
|
{
|
|
_criAtomSource.loop = isLoop;
|
|
}
|
|
|
|
public void SetIsSpeak(bool isSpeak)
|
|
{
|
|
_isSpeak = isSpeak;
|
|
}
|
|
|
|
public string GetCueSheetName()
|
|
{
|
|
if (_criAtomSource)
|
|
{
|
|
return _criAtomSource.cueSheet;
|
|
}
|
|
return "";
|
|
}
|
|
#endregion
|
|
} |