Created
June 3, 2015 15:14
-
-
Save karl-/fbb003bcff1bea2db211 to your computer and use it in GitHub Desktop.
This file contains 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 UnityEngine.UI; | |
using System.Collections; | |
using System.Linq; | |
[InitializeOnLoad] | |
public class HideShowCanvas : Editor | |
{ | |
static HideShowCanvas() | |
{ | |
EditorApplication.playmodeStateChanged += PlaymodeStateChanged; | |
} | |
static void PlaymodeStateChanged() | |
{ | |
Canvas canvas = (Canvas) Resources.FindObjectsOfTypeAll(typeof(Canvas)).FirstOrDefault(); | |
if(canvas == null) | |
return; | |
if(EditorApplication.isPlayingOrWillChangePlaymode) | |
{ | |
canvas.gameObject.SetActive(true); | |
} | |
else | |
{ | |
if( EditorPrefs.GetBool("DO_HIDE_CANVAS") ) | |
canvas.gameObject.SetActive(false); | |
} | |
} | |
[MenuItem("Edit/Toggle Canvas &c")] | |
static void Toggle() | |
{ | |
Canvas canvas = (Canvas) Resources.FindObjectsOfTypeAll(typeof(Canvas)).FirstOrDefault(); | |
canvas.gameObject.SetActive(!canvas.gameObject.activeSelf); | |
EditorPrefs.SetBool("DO_HIDE_CANVAS", !canvas.gameObject.activeSelf); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment