NxrPreRender.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2016 Nibiru. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using UnityEngine;
  15. /// Clears the entire screen. This script and NxrPostRender work together
  16. /// to draw the whole screen in XR Mode. There should be exactly one of each
  17. /// component in any NXR-enabled scene. It is part of the _NxrCamera_
  18. /// prefab, which is included in _NxrMain_. The NxrViewer script will
  19. /// create one at runtime if the scene doesn't already have it, so generally
  20. /// it is not necessary to manually add it unless you wish to edit the _Camera_
  21. /// component that it controls.
  22. namespace Nxr.Internal
  23. {
  24. [RequireComponent(typeof(Camera))]
  25. [AddComponentMenu("NXR/Internal/NxrPreRender")]
  26. public class NxrPreRender : MonoBehaviour
  27. {
  28. public Camera cam { get; private set; }
  29. void Awake()
  30. {
  31. cam = GetComponent<Camera>();
  32. }
  33. void Reset()
  34. {
  35. #if UNITY_EDITOR
  36. // Member variable 'cam' not always initialized when this method called in Editor.
  37. // So, we'll just make a local of the same name.
  38. var cam = GetComponent<Camera>();
  39. #endif
  40. cam.clearFlags = CameraClearFlags.SolidColor;
  41. cam.backgroundColor = Color.black;
  42. cam.cullingMask = 0;
  43. cam.useOcclusionCulling = false;
  44. cam.depth = -100;
  45. cam.farClipPlane = 100;
  46. if (NxrGlobal.isVR9Platform)
  47. {
  48. cam.clearFlags = CameraClearFlags.Nothing;
  49. }
  50. }
  51. }
  52. }