dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.47k stars 463 forks source link

[Request] What about a LayerMask attribute? #341

Open NumidWasNotAvailable opened 1 year ago

NumidWasNotAvailable commented 1 year ago

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.

Henri-J-Norden commented 1 year ago

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...

TylerTemp commented 9 months ago

So why not just:

public LayerMask myLayerMask;

{0HO3T~7%}F(NXPOPV~2E)B

this value can also be directly used as raycast parameter.