Skip to content

Instantly share code, notes, and snippets.

@rob5300
Created August 21, 2019 14:26
Show Gist options
  • Save rob5300/0301807045ea5a0e32d1e2551d884a7a to your computer and use it in GitHub Desktop.
Save rob5300/0301807045ea5a0e32d1e2551d884a7a to your computer and use it in GitHub Desktop.
Applies preset layermask on scene open and restores it on scene closed. Made for use in custom ui prefab editing scenes to show the UI layer automatically.
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
/// <summary>
/// Applies preset layermask on scene open and restores it on scene closed.
/// Made for use in custom ui prefab editing scenes to show the UI layer automatically.
/// </summary>
[ExecuteInEditMode]
public class CanvasEditorHelper : MonoBehaviour
{
public LayerMask MaskPreset;
private LayerMask oldMask;
private void OnEnable()
{
oldMask = Tools.visibleLayers;
Tools.visibleLayers = MaskPreset;
}
private void OnDestroy()
{
Tools.visibleLayers = oldMask;
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment