AMAudioAction.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using UnityEngine;
  3. [Serializable]
  4. public class AMAudioAction : AMAction
  5. {
  6. public override void execute(int frameRate, float delay, string trackId)
  7. {
  8. if (!this.audioSource || !this.audioClip)
  9. {
  10. return;
  11. }
  12. AMTween.PlayAudio(this.audioSource, AMTween.Hash(new object[]
  13. {
  14. "trackid",
  15. trackId,
  16. "delay",
  17. base.getWaitTime(frameRate, delay),
  18. "audioclip",
  19. this.audioClip,
  20. "loop",
  21. this.loop
  22. }));
  23. }
  24. public string ToString(int codeLanguage, int frameRate, string audioClipVarName)
  25. {
  26. if (this.audioClip == null || this.audioSource == null)
  27. {
  28. return null;
  29. }
  30. string text = string.Empty;
  31. if (codeLanguage == 0)
  32. {
  33. string text2 = text;
  34. text = string.Concat(new object[]
  35. {
  36. text2,
  37. "AMTween.PlayAudio(obj.gameObject, AMTween.Hash (\"delay\", ",
  38. base.getWaitTime(frameRate, 0f),
  39. "f, \"audioclip\", ",
  40. audioClipVarName,
  41. ", \"loop\", ",
  42. this.loop.ToString().ToLower(),
  43. "));"
  44. });
  45. }
  46. else
  47. {
  48. string text2 = text;
  49. text = string.Concat(new object[]
  50. {
  51. text2,
  52. "AMTween.PlayAudio(obj.gameObject, {\"delay\": ",
  53. base.getWaitTime(frameRate, 0f),
  54. ", \"audioclip\": ",
  55. audioClipVarName,
  56. ", \"loop\": ",
  57. this.loop.ToString().ToLower(),
  58. "});"
  59. });
  60. }
  61. return text;
  62. }
  63. public ulong getTimeInSamples(int frequency, float time)
  64. {
  65. return (ulong)((float)(44100 / frequency * frequency) * time);
  66. }
  67. public int getNumberOfFrames(int frameRate)
  68. {
  69. if (!this.audioClip)
  70. {
  71. return -1;
  72. }
  73. if (this.loop)
  74. {
  75. return -1;
  76. }
  77. return Mathf.CeilToInt(this.audioClip.length * (float)frameRate);
  78. }
  79. public override AnimatorTimeline.JSONAction getJSONAction(int frameRate)
  80. {
  81. if (!this.audioSource || !this.audioClip)
  82. {
  83. return null;
  84. }
  85. return new AnimatorTimeline.JSONAction
  86. {
  87. method = "playaudio",
  88. go = this.audioSource.gameObject.name,
  89. delay = base.getWaitTime(frameRate, 0f),
  90. strings = new string[]
  91. {
  92. this.audioClip.name
  93. },
  94. bools = new bool[]
  95. {
  96. this.loop
  97. }
  98. };
  99. }
  100. public AudioSource audioSource;
  101. public AudioClip audioClip;
  102. public bool loop;
  103. }