Search Unity

How To Lock Layers By Editor Script?

Discussion in 'Immediate Mode GUI (IMGUI)' started by fighder, Jul 1, 2016.

  1. fighder

    fighder

    Joined:
    Feb 1, 2015
    Posts:
    17
    Is there some way I can access the Layers and lock them by name or index? I can't seem to find an answer on google, so I was wondering if this is even possible.
     
  2. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Ahhh... its not like Photoshop.

    I wouldnt think of it like that. Think of Layers as more of a Masking flag, for Camera use mainly.

    So any GameObject can belong to just a single Category (Layer), but the Camera can show multiple Categories (Layer Mask can include many) for GameObjects belonging/assigned to those Categories.

    What are you trying to do? :p
     
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,237
  4. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    If you want to have a bit more flexibility than the built in layers, I highly recommend ProGroups. It adds great flexibility to the editor and makes locking objects, hiding objects and selecting entire groups a breeze.
     
  5. fighder

    fighder

    Joined:
    Feb 1, 2015
    Posts:
    17
    I came across that answer, but it didn't seem to make sense to me. I couldn't find Tools.lockedLayers in the api page, and Tools.visibleLayers seem return an int? I am not exactly sure how to use Tools.visibleLayers to lock the layer.

    I am not concern with masking nor fiddling with hidding objects in the camera through flags. I am just extending the Unity editor for a level editor and I need to lock game objects of a certain layers to make sure they don't get selected when I select a group of objects from a different layer.
     
  6. fighder

    fighder

    Joined:
    Feb 1, 2015
    Posts:
    17
    I got it working. Turns out Unity just didn't list Tools.lockedLayers. I was able to toggle it with Tools.lockedLayers ^= 1<<LayerMask.NameToLayer();
     
    Lars-Steenhoff and IzzySoft like this.
  7. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,070
    What does this do?

    Can I now make an editor menu that has the layer so I can toggle them?
     
    Last edited: Dec 30, 2017
  8. FinnTess

    FinnTess

    Joined:
    Jun 10, 2018
    Posts:
    1
    OMG YOU THE ONLY ONE WHO FIND IT XD THX !!!