Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LayerMaskExtensions
using System.Collections.Generic;
using UnityEngine;
namespace Giacomelli.Framework
{
public static class LayerMaskExtensions
{
public static bool HasLayer(this LayerMask mask, int layer) => mask == (mask | (1 << layer));
public static IEnumerable<string> ToNames(this LayerMask mask)
{
// Unity generates 32 layers.
// https://docs.unity3d.com/ScriptReference/GameObject-layer.html
for (int i = 0; i < 32; i++)
{
if (mask.HasLayer(i))
yield return LayerMask.LayerToName(i);
}
}
public static string JoinNames(this LayerMask mask, string separator = ", ")
{
return string.Join(separator, mask.ToNames());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment