public void SetLayerTransformable(int objectLayer, bool isTransformable) { if (isTransformable) { _transformableLayers = LayerEx.SetLayerBit(_transformableLayers, objectLayer); } else { _transformableLayers = LayerEx.ClearLayerBit(_transformableLayers, objectLayer); } }
public void SetLayerSnapDestination(int objectLayer, bool isSnapDestination) { if (isSnapDestination) { _snapDestinationLayers = LayerEx.SetLayerBit(_snapDestinationLayers, objectLayer); } else { _snapDestinationLayers = LayerEx.ClearLayerBit(_snapDestinationLayers, objectLayer); } }
/// <summary> /// Renders a layer mask field which can be used to mask/unmask different /// combinations of layers. /// </summary> public static int LayerMaskField(GUIContent content, int layerMask) { // Store all layer names for easy access List <string> allLayerNames = LayerEx.GetAllLayerNames(); // We first need to build a mask that is mapped to each element in 'allLayerNames'. // A 0 bit indicates that the layer with the same index as the bit position is masked. int indexMask = 0; for (int layerNameIndex = 0; layerNameIndex < allLayerNames.Count; ++layerNameIndex) { // If the layer is set inside the layer mask, set the bit in the index mask also string layerName = allLayerNames[layerNameIndex]; if (LayerEx.IsLayerBitSet(layerMask, LayerMask.NameToLayer(layerName))) { indexMask |= (1 << layerNameIndex); } } // Now we need to show the mask field to the user and use the returned index mask // to rebuild the actual layer mask. int resultMask = layerMask; int newIndexMask = EditorGUILayout.MaskField(content, indexMask, allLayerNames.ToArray()); for (int layerNameIndex = 0; layerNameIndex < allLayerNames.Count; ++layerNameIndex) { // Sync the index mask with the layer mask string layerName = allLayerNames[layerNameIndex]; if (((newIndexMask >> layerNameIndex) & 0x1) != 0) { resultMask = LayerEx.SetLayerBit(resultMask, LayerMask.NameToLayer(layerName)); } else { resultMask = LayerEx.ClearLayerBit(resultMask, LayerMask.NameToLayer(layerName)); } } return(resultMask); }