namespace Fungus {
using System ;
using UnityEngine ;
using UnityEngine.Serialization ;
[ CommandInfo ( "Audio" ,
"Play Usfxr Sound" ,
"Plays a usfxr synth sound. Use the usfxr editor [Tools > Fungus > Utilities > Generate usfxr Sound Effects] to create the SettingsString. Set a ParentTransform if using positional sound. See https://github.com/zeh/usfxr for more information about usfxr." ) ]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class PlayUsfxrSound : Command
{
protected SfxrSynth _ synth = new SfxrSynth ( ) ;
[Tooltip("Transform to use for positional audio")]
public Transform ParentTransform = null ;
[Tooltip("Settings string which describes the audio")]
public StringDataMulti _ SettingsString = new StringDataMulti ( "" ) ;
[Tooltip("Time to wait before executing the next command")]
public float waitDuration = 0 ;
//Call this if the settings have changed
protected void UpdateCache ( ) {
if ( _ SettingsString . Value ! = null ) {
_ synth . parameters . SetSettingsString ( _ SettingsString . Value ) ;
_ synth . CacheSound ( ) ;
}
}
public void Awake ( ) {
//Always build the cache on awake
UpdateCache ( ) ;
}
public override void OnEnter ( ) {
_ synth . SetParentTransform ( ParentTransform ) ;
_ synth . Play ( ) ;
if ( waitDuration = = 0f )
{
Continue ( ) ;
}
else
{
Invoke ( "DoWait" , waitDuration ) ;
}
}
protected void DoWait ( )
{
Continue ( ) ;
}
public override string GetSummary ( ) {
if ( String . IsNullOrEmpty ( _ SettingsString . Value ) ) {
return "Settings String hasn't been set!" ;
}
if ( ParentTransform ! = null ) {
return "" + ParentTransform . name + ": " + _ SettingsString . Value ;
}
return "Camera.main: " + _ SettingsString . Value ;
}
public override Color GetButtonColor ( ) {
return new Color32 ( 1 2 8 , 2 0 0 , 2 0 0 , 2 5 5 ) ;
}
#region Backwards compatibility
[HideInInspector] [ FormerlySerializedAs ( "SettingsString" ) ] public String SettingsStringOLD ;
protected virtual void OnEnable ( )
{
if ( SettingsStringOLD ! = "" )
{
_ SettingsString . Value = SettingsStringOLD ;
SettingsStringOLD = "" ;
}
}
# endregion
}
}