NAudioClip.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using UnityEngine;
  3. namespace FairyGUI
  4. {
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. public class NAudioClip
  9. {
  10. public static Action<AudioClip> CustomDestroyMethod;
  11. /// <summary>
  12. ///
  13. /// </summary>
  14. public DestroyMethod destroyMethod;
  15. /// <summary>
  16. ///
  17. /// </summary>
  18. public AudioClip nativeClip;
  19. /// <summary>
  20. ///
  21. /// </summary>
  22. /// <param name="audioClip"></param>
  23. public NAudioClip(AudioClip audioClip)
  24. {
  25. nativeClip = audioClip;
  26. }
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. public void Unload()
  31. {
  32. if (nativeClip == null)
  33. return;
  34. if (destroyMethod == DestroyMethod.Unload)
  35. Resources.UnloadAsset(nativeClip);
  36. else if (destroyMethod == DestroyMethod.Destroy)
  37. UnityEngine.Object.DestroyImmediate(nativeClip, true);
  38. else if (destroyMethod == DestroyMethod.Custom)
  39. {
  40. if (CustomDestroyMethod == null)
  41. Debug.LogWarning("NAudioClip.CustomDestroyMethod must be set to handle DestroyMethod.Custom");
  42. else
  43. CustomDestroyMethod(nativeClip);
  44. }
  45. nativeClip = null;
  46. }
  47. /// <summary>
  48. ///
  49. /// </summary>
  50. /// <param name="audioClip"></param>
  51. public void Reload(AudioClip audioClip)
  52. {
  53. if (nativeClip != null && nativeClip != audioClip)
  54. Unload();
  55. nativeClip = audioClip;
  56. }
  57. }
  58. }