BFX_RenderDepth.cs 557 B

123456789101112131415161718192021222324
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BFX_RenderDepth : MonoBehaviour
  5. {
  6. DepthTextureMode defaultMode;
  7. void OnEnable()
  8. {
  9. var cam = GetComponent<Camera>();
  10. defaultMode = cam.depthTextureMode;
  11. if (cam.renderingPath == RenderingPath.Forward)
  12. {
  13. cam.depthTextureMode |= DepthTextureMode.Depth;
  14. }
  15. }
  16. // Update is called once per frame
  17. void OnDisable()
  18. {
  19. GetComponent<Camera>().depthTextureMode = defaultMode;
  20. }
  21. }