UGUI of MaskableGraphic

MaskableGraphic inherited from Graphic, and inherited IClippable, IMaskable, IMaterialModifier three interfaces. It is RawImage, Image and Text of the parent class.

 

Methods inherited from Graphic of:

OnEnable: Set m_ShouldRecalculateStencil (the need to recalculate template) is true, calling UpdateClipParent (updated cut of the parent object), call SetMaterialDirty (set made of dirty, Graphic function). If Mask components, call the static function MaskUtilities.NotifyStencilStateChanged, recalculated Mask.

OnDisable: m_ShouldRecalculateStencil set to true, and in turn call SetMaterialDirty UpdateClipParent. Remove m_MaskMaterial in StencilMaterial in and put m_MaskMaterial set to null. If Mask components, call the static function MaskUtilities.NotifyStencilStateChanged.

OnTransformParentChanged (when the parent object changes) : Set m_ShouldRecalculateStencil is true, in turn call UpdateClipParent, SetMaterialDirty.

OnCanvasHierarchyChanged (Canvas status change of the parent object): m_ShouldRecalculateStencil set to true, turn call UpdateClipParent, SetMaterialDirty.

 

Look UpdateClipParent code:

     private void UpdateClipParent()
        {
            var newParent = (maskable && IsActive()) ? MaskUtilities.GetRectMaskForClippable(this) : null;

            // if the new parent is different OR is now inactive
            if (m_ParentMask != null && (newParent != m_ParentMask || !newParent.IsActive()))
            {
                m_ParentMask.RemoveClippable(this);
                UpdateCull(false);
            }

            // don't re-add it if the newparent is inactive
            if (newParent != null && newParent.IsActive())
                newParent.AddClippable(this);

            m_ParentMask = newParent;
        }

Call MaskUtilities.GetRectMaskForClippable find the parent object RectMask2D components (RectMask2D components can be cut according to RectTransform child object child object parent RectTransform beyond the scope of the section will be cut off).

If newParent not equal m_ParentMask or newParent is not activated, it calls RemoveClippable (called RemoveClippable in clippable.SetClipRect (new Rect (), false) closed rectangular cut, and to remove themselves from RectMask2D of m_ClipTargets in), and then update removed.

If newParent activated, calls AddClippable (to add yourself to RectMask2D of m_ClipTargets in).

The newParent assigned to m_ParentMask.

 

Methods inherited from IClippable of:

RecalculateClipping (Called when IClippable status of the parent object changes): Call UpdateClipParent.

Cull: If validRect clipRect is false or do not coincide with rootCanvasRect rectangular, call UpdateCull. UpdateCull, if the input is not equal to canvasRenderer.cull Cull, the canvasRenderer.cull = cull, callback m_OnCullStateChanged , the Graphic OnCullingChanged recall function.

SetClipRect: validRect the passed value, select open or close canvasRenderer rectangular cut.

 

Methods inherited from IMaskable of:

RecalculateMasking: remove StencilMaterial in m_MaskMaterial, the m_MaskMaterial set to null, m_ShouldRecalculateStencil set to true, call SetMaterialDirty function.

 

Methods inherited from IMaterialModifier of:

     public virtual Material GetModifiedMaterial(Material baseMaterial)
        {
            var toUse = baseMaterial;

            if (m_ShouldRecalculateStencil)
            {
                var rootCanvas = MaskUtilities.FindRootSortOverrideCanvas(transform);
                m_StencilValue = maskable ? MaskUtilities.GetStencilDepth(transform, rootCanvas) : 0;
                m_ShouldRecalculateStencil = false;
            }

            // if we have a enabled Mask component then it will
            // generate the mask material. This is an optimisation
            // it adds some coupling between components though :(
            Mask maskComponent = GetComponent<Mask>();
            if (m_StencilValue > 0 && (maskComponent == null || !maskComponent.IsActive()))
            {
                var maskMat = StencilMaterial.Add(toUse, (1 << m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (1 << m_StencilValue) - 1, 0);
                StencilMaterial.Remove(m_MaskMaterial);
                m_MaskMaterial = maskMat;
                touse = m_MaskMaterial;
            }
            return toUse;
        }

GetModifiedMaterial: If m_ShouldRecalculateStencil is true, get rootCanvas by MaskUtilities.FindRootSortOverrideCanvas, according maskable, to m_StencilValue assigned template depth or 0, m_ShouldRecalculateStencil set to false .

If greater than 0 and Mask m_StencilValue component does not exist or is not activated, put baseMaterial, stencilID, operation and other parameters to StencilMaterial in m_MaskMaterial and replace with a new material.

Guess you like

Origin www.cnblogs.com/pj2933/p/11028220.html