Exemplo n.º 1
0
        private void Startup()
        {
            if (_initialized)
            {
                return;
            }

            _initialized = true;

            _camera = GetComponent <Camera>();
            if (_camera.actualRenderingPath != RenderingPath.DeferredShading)
            {
                if (_camera.name == "SceneCamera")
                {
                    Log.Warn("Scene Camera is in 2D mode or '{0}' mode, Wet Decals will not be rendered in scene view.", _camera.actualRenderingPath);
                }
                else
                {
                    Log.Error("Camera '{0}' rendering path is '{1}', 'DeferredShading' is required for Wet Decals to render.", _camera.name, _camera.actualRenderingPath);
                }
            }

            _cmd = new CommandBuffer {
                name = "Wet Surface Decals"
            };

            _camera.AddCommandBuffer(CameraEvent.BeforeReflections, _cmd);
            if (_camera.commandBufferCount < 1)
            {
                Log.Error("Failed to attach CommandBuffer");
            }

            _decalRenderer   = new WetDecalRenderer(_camera);
            _gbufferModifier = new WetAttributeModifier(_camera)
            {
                AmbientDarkenStrength = _ambientModificationFactor
            };

#if UNITY_EDITOR
            if (!_appliedEditorRestartHack)
            {
                _appliedEditorRestartHack = true;
                gameObject.AddComponent <EditorRestartHack>().Apply(this);
            }
#endif
        }
Exemplo n.º 2
0
        private void Teardown()
        {
            if (!_initialized)
            {
                return;
            }

            _initialized = false;

            _decalRenderer.Dispose();
            _gbufferModifier.Dispose();

            _camera.RemoveCommandBuffer(CameraEvent.BeforeReflections, _cmd);
            _cmd.Dispose();

            _cmd             = null;
            _decalRenderer   = null;
            _gbufferModifier = null;
        }