JetBrains / JetBrains/resharper-unity
Add debug type view for LayerMask
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 142
- PR merge metrics
- No merged PRs in 30d
Description
Add a debugger extension to render `LayerMask` as the name(s) of the layer(s) in the int value. This can be achieved by calling `UnityEngine.LayerMask.LayerToName(int)` for each bit set in the layer mask.
This should also be done for `SerializedProperty.intValue` when `propertyType == SerializedPropertyType.LayerMask`, and for `GameObject.layer`. Investigate other well known layer fields.
The problem with this is that layer mask names should be cached. They never change over the lifetime of a player, and rarely change in the editor (the user would have to interactively edit a layer, or call a user script during a debug session) and since a layer value is a bit mask, there will be several unnecessary invocations of `LayerMask.LayerToName`, especially since `GameObject.layer` is shown as part of `GameObject`'s value presenter - given a list of `GameObject` instances, this could cause a lot of unnecessary invocations. It is unlikely that a layer value will have more than 1 or 2 bits set, but theoretically, it could have 32 bits set. Ideally, the debugger API would provide a mechanism for caching in a known "evaluation context", so layer names could be safely reused.
An alternative is to use the protocol to pass the known layers that have been parsed from `ProjectSettings/TagManager.asset`. This would work similar to caching, and would even be updated when changes are made. It might be possible to be out of date with a player, if it is build and then layers are edited, but that risk is already there with scripts.
Contributor guide
Research direction
Start with the debugger extension entry points for LayerMask, SerializedProperty.intValue when propertyType is LayerMask, and GameObject.layer. Compare calling UnityEngine.LayerMask.LayerToName(int) with the protocol and ProjectSettings/TagManager.asset approach described in the issue. Done means layer values render their names, other well-known layer fields are considered, and repeated layer-name lookups use a safe cache.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, unity
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100