Beispiel #1
0
        // This method defines the way in which renderers are initialized
        private void UpdateRenderers()
        {
            if (renderersDirty)
            {
                ClearRenderers();

                // Find all renderers which should be controlled with this Highlighter component
                List <Renderer> renderers = new List <Renderer>();
                GrabRenderers(tr, renderers);

                // Cache found renderers
                for (int i = 0, imax = renderers.Count; i < imax; i++)
                {
                    if (renderers[i] == null)
                    {
                        continue;
                    }
                    GameObject          rg       = renderers[i].gameObject;
                    HighlighterRenderer renderer = rg.GetComponent <HighlighterRenderer>();
                    if (renderer == null)
                    {
                        renderer = rg.AddComponent <HighlighterRenderer>();
                    }
                    renderer.SetState(true);

                    renderer.Initialize(opaqueMaterial, transparentShader);
                    highlightableRenderers.Add(renderer);
                }

                renderersDirty = false;
            }
        }
Beispiel #2
0
 // Clear cached renderers
 private void ClearRenderers()
 {
     for (int i = highlightableRenderers.Count - 1; i >= 0; i--)
     {
         HighlighterRenderer renderer = highlightableRenderers[i];
         renderer.SetState(false);
     }
     highlightableRenderers.Clear();
 }
Beispiel #3
0
        //
        private void FillBufferInternal(CommandBuffer buffer, Mode m, bool depthAvailable)
        {
            UpdateRenderers();

            bool isHighlighter = once || flashing || (transitionValue > 0f);
            bool isOccluder    = occluder && (seeThrough || !depthAvailable);

            // Update mode
            mode = Mode.None;
            if (isHighlighter)
            {
                mode = seeThrough ? Mode.HighlighterSeeThrough : Mode.Highlighter;
            }
            else if (isOccluder)
            {
                mode = seeThrough ? Mode.OccluderSeeThrough : Mode.Occluder;
            }

            if (mode == Mode.None || mode != m)
            {
                return;
            }

            if (isHighlighter)
            {
                // ZTest = (seeThrough ? Always : LEqual), StencilRef = 1
                UpdateShaderParams(seeThrough, true);
            }
            else if (isOccluder)
            {
                // ZTest = LEqual, StencilRef = seeThrough ? 1 : 0
                UpdateShaderParams(false, seeThrough);
            }
            UpdateColors();

            // Fill CommandBuffer with this highlighter rendering commands
            for (int i = highlightableRenderers.Count - 1; i >= 0; i--)
            {
                // To avoid null-reference exceptions when cached renderer has been removed but ReinitMaterials wasn't been called
                HighlighterRenderer renderer = highlightableRenderers[i];
                if (renderer == null)
                {
                    highlightableRenderers.RemoveAt(i);
                }
                // Try to fill buffer
                else if (!renderer.FillBuffer(buffer))
                {
                    highlightableRenderers.RemoveAt(i);
                    renderer.SetState(false);
                }
            }
        }