12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #if UNITY_EDITOR
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- using System.Reflection;
- namespace KairoEngine.SFX
- {
- public static class SFXUtil
- {
- public static void PlayClip(AudioClip clip, int startSample = 0, bool loop = false)
- {
- System.Reflection.Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
- System.Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
- System.Reflection.MethodInfo method = audioUtilClass.GetMethod(
- "PlayClip",
- System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public,
- null,
- new System.Type[] { typeof(AudioClip), typeof(int), typeof(bool) },
- null
- );
- method.Invoke(
- null,
- new object[] { clip, startSample, loop }
- );
- }
- public static void StopClip(AudioClip clip) {
- Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
- System.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 StopAllClips () {
- Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
- System.Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
- MethodInfo method = audioUtilClass.GetMethod(
- "StopAllClips",
- BindingFlags.Static | BindingFlags.Public
- );
- method.Invoke(
- null,
- null
- );
- }
- }
- }
- #endif
|