Skip to content

Instantly share code, notes, and snippets.

@karl-
Created June 3, 2015 15:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karl-/fbb003bcff1bea2db211 to your computer and use it in GitHub Desktop.
Save karl-/fbb003bcff1bea2db211 to your computer and use it in GitHub Desktop.
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