Last active
October 24, 2018 11:31
-
-
Save anchan828/13c901d5daa9f7502d65 to your computer and use it in GitHub Desktop.
コンパイルエラーが出たまま再生ボタンを押すと、ドラクエの呪いの効果音を再生する
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 characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assets/Editor
フォルダに効果音を突っ込む