using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace UnityEditor {
public static class AudioUtility {
public static void PlayClip(AudioClip clip , int startSample , bool loop) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"PlayClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip),
typeof(Int32),
typeof(Boolean)
},
null
);
method.Invoke(
null,
new object[] {
clip,
startSample,
loop
}
);
}
public static void PlayClip(AudioClip clip , int startSample) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"PlayClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip),
typeof(Int32)
},
null
);
method.Invoke(
null,
new object[] {
clip,
startSample
}
);
}
public static void PlayClip(AudioClip clip) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"PlayClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip)
},
null
);
method.Invoke(
null,
new object[] {
clip
}
);
}
public static void StopClip(AudioClip clip) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"StopClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip)
},
null
);
method.Invoke(
null,
new object[] {
clip
}
);
}
public static void PauseClip(AudioClip clip) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"PauseClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip)
},
null
);
method.Invoke(
null,
new object[] {
clip
}
);
}
public static void ResumeClip(AudioClip clip) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"ResumeClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip)
},
null
);
method.Invoke(
null,
new object[] {
clip
}
);
}
public static void LoopClip(AudioClip clip , bool on) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"LoopClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip),
typeof(bool)
},
null
);
method.Invoke(
null,
new object[] {
clip,
on
}
);
}
public static bool IsClipPlaying(AudioClip clip) {
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"IsClipPlaying",
BindingFlags.Static | BindingFlags.Public
);
bool playing = (bool)method.Invoke(
null,
new