コード例 #1
0
        private void ApplyMaskToUIElement(Graphic mGraphic, Mask maskTarget)
        {
            bool maskeeMaterialUsed = MaskeeMaterialUsed(mGraphic.material, maskTarget);

            if (IsSupported2DShader(mGraphic.material.shader) || maskeeMaterialUsed)
            {
                UIMaterialModifier modifier = mGraphic.gameObject.GetComponent <UIMaterialModifier>();
                if (modifier == null)
                {
                    modifier = mGraphic.gameObject.AddComponent <UIMaterialModifier>();
                }

                if (!maskeeMaterialUsed)
                {
                    mGraphic.material = maskTarget.SpritesAlphaMaskWorldCoords;
                }
            }
        }
コード例 #2
0
        private void UpdateUIMaterials(List <Graphic> differentGraphics, Matrix4x4 worldToMask, Vector4 tilingAndOffset)
        {
            foreach (Graphic graphic in differentGraphics)
            {
#if UNITY_EDITOR
                if (maskeeVersion == 0)
                {
                    VersionUpgradeMaskees(graphic);
                }
#endif

                if ((graphic.material.shader == MaskedSpriteWorldCoordsShader) ||
                    (graphic.material.shader == MaskedUnlitWorldCoordsShader))
                {
                    UIMaterialModifier modifier = graphic.GetComponent <UIMaterialModifier>();
                    if (modifier == null)
                    {
                        modifier = graphic.gameObject.AddComponent <UIMaterialModifier>();
                    }

                    Canvas    currentCanvas = graphic.canvas;
                    Matrix4x4 canvasMatrix  = Matrix4x4.identity;

                    bool renderModeScreenSpace = currentCanvas != null && (currentCanvas.renderMode == RenderMode.ScreenSpaceOverlay ||
                                                                           (currentCanvas.renderMode == RenderMode.ScreenSpaceCamera && currentCanvas.worldCamera == null));

                    bool enableScreenSpaceUI = false;

                    if (renderModeScreenSpace)
                    {
                        RectTransform canvasRect = currentCanvas.GetComponent <RectTransform>();
                        canvasMatrix        = Matrix4x4.TRS(canvasRect.rect.size / 2 * currentCanvas.scaleFactor, Quaternion.identity, Vector3.one * currentCanvas.scaleFactor);
                        enableScreenSpaceUI = true;
                    }

                    modifier.SetMaskToMaskee(worldToMask * canvasMatrix, tilingAndOffset, ClampingBorder, IsMaskingEnabled, enableScreenSpaceUI,
                                             ClampAlphaHorizontally, ClampAlphaVertically, UseMaskAlphaChannel, graphic is Text);
                    modifier.UpdateAlphaTex(MainTex);

                    modifier.ApplyMaterialProperties();
                }
            }
        }