-
-
Save giacomelli/0b67968e915cdb1ffd2ae1c2000f5bad to your computer and use it in GitHub Desktop.
LayerMaskExtensions
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 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