Пример #1
0
        void OnDisable()
        {
            if (!actuallyEnabled)
            {
                return;
            }
            actuallyEnabled      = false;
            Camera.onPostRender -= PostRender;
            UnityEngine.Rendering.RenderPipelineManager.beginFrameRendering -= BeginFrameRendering;
            UnityEngine.Rendering.RenderPipelineManager.endCameraRendering  -= EndCameraRendering;
#if UNITY_EDITOR
            EditorApplication.update -= OnUpdate;
#endif
            // Gizmos can be null here if this GameObject was duplicated by a user in the hierarchy.
            if (gizmos != null)
            {
                Draw.builder.DiscardAndDisposeInternal();
                Draw.ingame_builder.DiscardAndDisposeInternal();
                gizmos.ClearData();
            }
#if MODULE_RENDER_PIPELINES_UNIVERSAL
            if (renderPassFeature != null)
            {
                ScriptableObject.DestroyImmediate(renderPassFeature);
                renderPassFeature = null;
            }
#endif
        }
Пример #2
0
        void BeginFrameRendering(ScriptableRenderContext context, Camera[] cameras)
        {
            RefreshRenderPipelineMode();

#if MODULE_RENDER_PIPELINES_UNIVERSAL
            if (detectedRenderPipeline == DetectedRenderPipeline.URP)
            {
                for (int i = 0; i < cameras.Length; i++)
                {
                    var cam = cameras[i];
                    if (cam.TryGetComponent <UniversalAdditionalCameraData>(out UniversalAdditionalCameraData data))
                    {
                        var renderer = data.scriptableRenderer;

                        // Ensure we don't add passes every frame, we only need to do this once
                        if (!scriptableRenderersWithPass.Contains(renderer))
                        {
                            // Use reflection to access the rendererFeatures on the scriptable renderer.
                            // That property is unfortunately protected and there is no other good way to add custom render passes from a script like this that I have found.
                            var rendererFeatures = renderer.GetType().GetProperty("rendererFeatures", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(renderer) as List <ScriptableRendererFeature>;
                            if (renderPassFeature == null)
                            {
                                renderPassFeature = ScriptableObject.CreateInstance <AlineURPRenderPassFeature>();
                            }

                            rendererFeatures.Add(renderPassFeature);
                            scriptableRenderersWithPass.Add(renderer);
                        }
                    }
                }
            }
#endif
        }