Is it possible to access Layer visibility and lock status via script?

I’m making a level editor and when an option is on in my EditorWindow script, I can select multiple gameobjects and add them to a collection.

I want to be able to select just the gameobjects in a particular layer, so when this option is on the other layers should be locked, but I’m unable to find any way to access layer properties from code.

Is it possible to do change layer’s lock and visibility from my script? Is there some clever way to do that?

Thanks!

Hahahaha!

I had an issue where I was unable to select objects in scene… You just gave me the explanation… XD

Anyway, you can toggle layer’s lock state by calling :

InternalEditorUtility.SetSortingLayerLocked(index, state);

Since it is hidden, you need to call it through reflection. Will you need help?

Edit:
With some further research, you might change it through Tools.visibleLayers and Tools.lockedLayers.