Search Unity

RectMask2D Clippable Layers

Discussion in 'Editor & General Support' started by Gdizzie, Aug 30, 2019.

  1. Gdizzie

    Gdizzie

    Joined:
    Apr 4, 2013
    Posts:
    19
    As the title suggests, is there an option for this somewhere that I'm missing? If there isn't, why isn't there an option for choosing which layers to clip in children? Are there any workarounds for this or a different way perhaps?

    Thanks.

    UPDATE:

    Just in case anybody else comes across this, you can actually call RemoveClippable on the RecMask2D class. It didn't seem flexible enough for me so I inherited from RectMask2D and made a public List of MaskableGraphics which I could edit in the inspector. You also need to override the default editor class for RectMask2D.

    Code (CSharp):
    1. public class RectMask2DCustom : RectMask2D
    2. {
    3.  
    4.     public List<MaskableGraphic> maskableGraphicsToIgnore = new List<MaskableGraphic>();
    5.     private List<IClippable> clippablesToRemove;
    6.    
    7.     void Start()
    8.     {
    9.         clippablesToRemove = maskableGraphicsToIgnore.ConvertAll( new Converter<MaskableGraphic,
    10.             IClippable> (MaskableGraphicToIClippable));
    11.        
    12.         foreach (IClippable iClippable in clippablesToRemove)
    13.         {
    14.             RemoveClippable(iClippable);
    15.         }
    16.     }
    17.    
    18.     IClippable MaskableGraphicToIClippable (MaskableGraphic mg)
    19.     {
    20.         return (IClippable)mg;
    21.     }
    22. }
    23.  
    Code (CSharp):
    1. using UnityEngine.UI;
    2.  
    3. namespace UnityEditor.UI
    4. {
    5.     [CustomEditor(typeof(RectMask2DCustom), true)]
    6.     [CanEditMultipleObjects]
    7.  
    8.     public class RectMask2DEditor : Editor
    9.     {
    10.  
    11.     }
    12. }
     
    Last edited: Sep 13, 2019