dbrizov / NaughtyAttributes

Attribute Extensions for Unity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Request] What about a LayerMask attribute?

NumidWasNotAvailable opened this issue · comments

LayerMaskAttribute would decorate int fields, with the ability to generate a layer mask. The value could be used for raycasting, for instance.

This would look like EnumFlagsAttribute, applied to the layers logic.

What do you think about it?

Again, I can propose an implementation.

I implemented this in my LayerMask branch with [Layer(mask=true)] or [SortingLayer(mask=true)]. There is also a [XRILayer(mask=true)] for the XR Interaction Toolkit in the LayerMaskXRI branch.

It should also be easy to add new LayerMask types, you just have to subclass
BaseLayerAttribute and provide correct implementations for:

string[] GetLayers();
int NameToLayer(string layerName);
string LayerToName(int layer);

Might make a pull request later, but it doesn't look like the owner is active anymore...