Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Reflection;
- using UnityEditor;
- [ExecuteInEditMode]
- public class SoundOnScriptReload : MonoBehaviour
- {
- [UnityEditor.Callbacks.DidReloadScripts]
- private static void OnScriptsReloaded()
- {
- var audioClip = (AudioClip)EditorGUIUtility.Load("Assets/Sounds/" + "ScriptsDone" + ".ogg");
- PlayClip(audioClip);
- }
- 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 StopAllClips()
- {
- Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
- Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
- MethodInfo method = audioUtilClass.GetMethod(
- "StopAllClips",
- BindingFlags.Static | BindingFlags.Public,
- null,
- new System.Type[] { },
- null
- );
- method.Invoke(
- null,
- new object[] { }
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement