示例#1
0
        virtual protected void ApplyClipping(UpdateContext context)
        {
#if UNITY_2018_2_OR_NEWER
            int cnt = _renderers.Count;
            for (int i = 0; i < cnt; i++)
            {
                Renderer renderer = _renderers[i].renderer;
                if (renderer == null)
                {
                    continue;
                }

                if (customCloneMaterials != null)
                {
                    helperMaterials.AddRange(_materialsBackup.Values);
                }
                else
                {
                    renderer.GetSharedMaterials(helperMaterials);
                }

                int cnt2 = helperMaterials.Count;
                for (int j = 0; j < cnt2; j++)
                {
                    Material mat = helperMaterials[j];
                    if (mat != null)
                    {
                        context.ApplyClippingProperties(mat, false);
                    }
                }

                helperMaterials.Clear();
            }
#else
            int cnt = _renderers.Count;
            for (int i = 0; i < cnt; i++)
            {
                Material[] mats = _renderers[i].materials;
                if (mats == null)
                {
                    continue;
                }

                int cnt2 = mats.Length;
                for (int j = 0; j < cnt2; j++)
                {
                    Material mat = mats[j];
                    if (mat != null)
                    {
                        context.ApplyClippingProperties(mat, false);
                    }
                }
            }
#endif
        }
示例#2
0
        virtual protected void ApplyClipping(UpdateContext context)
        {
#if UNITY_2018_2_OR_NEWER
            int cnt = _renderers.Count;
            for (int i = 0; i < cnt; i++)
            {
                _renderers[i].renderer.GetMaterials(helperMaterials);

                int cnt2 = helperMaterials.Count;
                for (int j = 0; j < cnt2; j++)
                {
                    Material mat = helperMaterials[j];
                    if (mat != null)
                    {
                        context.ApplyClippingProperties(mat, false);
                    }
                }

                helperMaterials.Clear();
            }
#else
            int cnt = _renderers.Count;
            for (int i = 0; i < cnt; i++)
            {
                RendererInfo ri   = _renderers[i];
                Material[]   mats = ri.materials;
                if (mats != null)
                {
                    int cnt2 = mats.Length;
                    for (int j = 0; j < cnt2; j++)
                    {
                        Material mat = mats[j];
                        if (mat != null)
                        {
                            context.ApplyClippingProperties(mat, false);
                        }
                    }
                }
            }
#endif
        }
示例#3
0
        override public void Update(UpdateContext context)
        {
            if (onUpdate != null)
            {
                onUpdate(context);
            }

            if (_shouldCloneMaterial)
            {
                CloneMaterials();
            }

            if (_supportMask)
            {
                int cnt = _renderers.Count;
                for (int i = 0; i < cnt; i++)
                {
                    RendererInfo ri   = _renderers[i];
                    Material[]   mats = ri.materials;
                    if (mats != null)
                    {
                        int cnt2 = mats.Length;
                        for (int j = 0; j < cnt2; j++)
                        {
                            Material mat = mats[j];
                            if (mat != null)
                            {
                                context.ApplyClippingProperties(mat, false);
                            }
                        }

                        if (cnt2 > 0 && _cloneMaterial && ri.renderer != null &&
                            !Material.ReferenceEquals(ri.renderer.sharedMaterial, mats[0]))
                        {
                            ri.renderer.sharedMaterials = mats;
                        }
                    }
                }
            }

            base.Update(context);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="alpha"></param>
        /// <param name="grayed"></param>
        public void Update(UpdateContext context, float alpha, bool grayed)
        {
            Stats.GraphicsCount++;

            if (_meshDirty)
            {
                _alpha = alpha;
                UpdateMeshNow();
            }
            else if (_alpha != alpha)
            {
                ChangeAlpha(alpha);
            }

            if (_propertyBlock != null && _blockUpdated)
            {
                meshRenderer.SetPropertyBlock(_propertyBlock);
                _blockUpdated = false;
            }

            if (_customMatarial != 0)
            {
                if ((_customMatarial & 2) != 0 && _material != null)
                {
                    context.ApplyClippingProperties(_material, false);
                }
            }
            else
            {
                if (_manager != null)
                {
                    if (_maskFlag == 1)
                    {
                        _material = _manager.GetMaterial((int)MaterialFlags.AlphaMask + _materialFlags, BlendMode.Normal, context.clipInfo.clipId);
                        context.ApplyAlphaMaskProperties(_material, false);
                    }
                    else
                    {
                        int matFlags = _materialFlags;
                        if (grayed)
                        {
                            matFlags |= (int)MaterialFlags.Grayed;
                        }

                        if (context.clipped)
                        {
                            if (context.stencilReferenceValue > 0)
                            {
                                matFlags |= (int)MaterialFlags.StencilTest;
                            }
                            if (context.rectMaskDepth > 0)
                            {
                                if (context.clipInfo.soft)
                                {
                                    matFlags |= (int)MaterialFlags.SoftClipped;
                                }
                                else
                                {
                                    matFlags |= (int)MaterialFlags.Clipped;
                                }
                            }

                            _material = _manager.GetMaterial(matFlags, blendMode, context.clipInfo.clipId);
                            if (_manager.firstMaterialInFrame)
                            {
                                context.ApplyClippingProperties(_material, true);
                            }
                        }
                        else
                        {
                            _material = _manager.GetMaterial(matFlags, blendMode, 0);
                        }
                    }
                }
                else
                {
                    _material = null;
                }

                if (!Material.ReferenceEquals(_material, meshRenderer.sharedMaterial))
                {
                    meshRenderer.sharedMaterial = _material;
                }
            }

            if (_maskFlag != 0)
            {
                if (_maskFlag == 1)
                {
                    _maskFlag = 2;
                }
                else
                {
                    if (_stencilEraser != null)
                    {
                        _stencilEraser.enabled = false;
                    }

                    _maskFlag = 0;
                }
            }
        }