Skip to content

Instantly share code, notes, and snippets.

@anchan828
Last active October 24, 2018 11:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anchan828/13c901d5daa9f7502d65 to your computer and use it in GitHub Desktop.
Save anchan828/13c901d5daa9f7502d65 to your computer and use it in GitHub Desktop.
コンパイルエラーが出たまま再生ボタンを押すと、ドラクエの呪いの効果音を再生する
using UnityEngine;
using UnityEditor;
using System.Reflection;
[InitializeOnLoad]
public class CompileError
{
// 効果音。自由に変更する
// http://commons.nicovideo.jp/material/nc32797
const string musicPath = "Assets/Editor/nc32797.wav";
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
static CompileError ()
{
EditorApplication.playmodeStateChanged += () => {
// 再生ボタンをおした時であること
if (!EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying)
return;
// SceneViewが存在すること
if (SceneView.sceneViews.Count == 0)
return;
EditorApplication.delayCall += () => {
var content = typeof(EditorWindow).GetField ("m_Notification", flags).GetValue (SceneView.sceneViews [0]) as GUIContent;
if (content != null && !string.IsNullOrEmpty (content.text)) {
GetAudioSource ().Play ();
}
};
};
}
static AudioSource GetAudioSource ()
{
var gameObjectName = "HideAudioSourceObject";
var gameObject = GameObject.Find (gameObjectName);
if (gameObject == null) {
//HideAndDontSaveフラグを立てて非表示・保存しないようにする
gameObject = EditorUtility.CreateGameObjectWithHideFlags (gameObjectName, HideFlags.HideAndDontSave, typeof(AudioSource));
}
var hideAudioSource = gameObject.GetComponent<AudioSource> ();
if (hideAudioSource.clip == null) {
hideAudioSource.clip = AssetDatabase.LoadAssetAtPath (musicPath, typeof(AudioClip)) as AudioClip;
}
return hideAudioSource;
}
}
@anchan828
Copy link
Author

  1. http://commons.nicovideo.jp/material/nc32797から効果音をダウンロード
  2. Assets/Editorフォルダに効果音を突っ込む
  3. コンパイルエラーが出たままエディタを再生させる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment