using System; using UnityEngine; [Serializable] public class AMAudioAction : AMAction { public override void execute(int frameRate, float delay, string trackId) { if (!this.audioSource || !this.audioClip) { return; } AMTween.PlayAudio(this.audioSource, AMTween.Hash(new object[] { "trackid", trackId, "delay", base.getWaitTime(frameRate, delay), "audioclip", this.audioClip, "loop", this.loop })); } public string ToString(int codeLanguage, int frameRate, string audioClipVarName) { if (this.audioClip == null || this.audioSource == null) { return null; } string text = string.Empty; if (codeLanguage == 0) { string text2 = text; text = string.Concat(new object[] { text2, "AMTween.PlayAudio(obj.gameObject, AMTween.Hash (\"delay\", ", base.getWaitTime(frameRate, 0f), "f, \"audioclip\", ", audioClipVarName, ", \"loop\", ", this.loop.ToString().ToLower(), "));" }); } else { string text2 = text; text = string.Concat(new object[] { text2, "AMTween.PlayAudio(obj.gameObject, {\"delay\": ", base.getWaitTime(frameRate, 0f), ", \"audioclip\": ", audioClipVarName, ", \"loop\": ", this.loop.ToString().ToLower(), "});" }); } return text; } public ulong getTimeInSamples(int frequency, float time) { return (ulong)((float)(44100 / frequency * frequency) * time); } public int getNumberOfFrames(int frameRate) { if (!this.audioClip) { return -1; } if (this.loop) { return -1; } return Mathf.CeilToInt(this.audioClip.length * (float)frameRate); } public override AnimatorTimeline.JSONAction getJSONAction(int frameRate) { if (!this.audioSource || !this.audioClip) { return null; } return new AnimatorTimeline.JSONAction { method = "playaudio", go = this.audioSource.gameObject.name, delay = base.getWaitTime(frameRate, 0f), strings = new string[] { this.audioClip.name }, bools = new bool[] { this.loop } }; } public AudioSource audioSource; public AudioClip audioClip; public bool loop; }