using System; namespace UnityEngine.XR.Interaction.Toolkit { /// /// Specifies Interaction Layers to use in XR interactions. /// [Serializable] public struct InteractionLayerMask : ISerializationCallbackReceiver { [SerializeField] uint m_Bits; int m_Mask; /// /// Implicitly converts an InteractionLayerMask to an integer. /// /// The mask to be converted. /// Returns the integer value of the Interaction Layer Mask. public static implicit operator int(InteractionLayerMask mask) { return mask.m_Mask; } /// /// Implicitly converts an integer to an InteractionLayerMask. /// /// The mask value. /// Returns the Interaction Layer Mask for the integer value. public static implicit operator InteractionLayerMask(int intVal) { InteractionLayerMask mask; mask.m_Mask = intVal; mask.m_Bits = (uint)intVal; return mask; } /// /// Converts an interaction layer mask value to an integer value. /// /// The integer value equivalent to this Interaction Layer Mask. public int value { get => m_Mask; set { m_Mask = value; m_Bits = (uint)value; } } /// /// Given a layer number, returns the name of the Interaction Layer as defined in either a Builtin or a User Layer. /// /// The interaction layer bit index. /// Returns the name of the supplied Interaction Layer value. public static string LayerToName(int layer) { if (layer < 0 || layer >= InteractionLayerSettings.layerSize) return string.Empty; return InteractionLayerSettings.Instance.GetLayerNameAt(layer); } /// /// Given an Interaction Layer name, returns the index as defined by either a Builtin or a User Layer. /// /// The interaction layer name. /// Returns the index of the supplied Interaction Layer name. public static int NameToLayer(string layerName) { return InteractionLayerSettings.Instance.GetLayer(layerName); } /// /// Given a set of Interaction Layer names, returns the equivalent mask for all of them. /// /// The interaction layer names to be converted to a mask /// Returns the equivalent mask for all the supplied Interaction Layer names. /// Throws when is . public static int GetMask(params string[] layerNames) { if (layerNames == null) throw new ArgumentNullException(nameof(layerNames)); var mask = 0; foreach (string name in layerNames) { var layer = NameToLayer(name); if (layer != -1) mask |= 1 << layer; } return mask; } /// /// See . /// public void OnAfterDeserialize() { m_Mask = (int)m_Bits; } /// /// See . /// public void OnBeforeSerialize() { } } }