Created
July 30, 2018 15:40
-
-
Save Syy9/b26fc40a0469daddaed4395e9b27a8a8 to your computer and use it in GitHub Desktop.
Revisions
-
Syy9 created this gist
Jul 30, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.Linq; using System.Reflection; using System; public static class AutoPlayPreviewAudio { [InitializeOnLoadMethod] static void Init() { Selection.selectionChanged += OnSelectionChanged; } private static void OnSelectionChanged() { var clip = Selection.objects.Where(obj => obj is AudioClip).FirstOrDefault(); if(clip == null) return; var unityEditorAssembly = typeof(AudioImporter).Assembly; var audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil"); var method = audioUtilClass.GetMethod( "PlayClip", BindingFlags.Static | BindingFlags.Public, null, new Type[] {typeof(AudioClip)}, null ); method.Invoke(null, new object[] {clip}); } }