You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. public class FogVolumePriority : MonoBehaviour {
  6. public Camera GameCamera;
  7. public int FogOrderCameraAbove=1;
  8. public int FogOrderCameraBelow=-1;
  9. public float HeightThreshold=30;
  10. public FogVolume thisFog;
  11. FogVolumeData _FogVolumeData;
  12. public float CurrentHeight;
  13. // public bool AutoAssignCameraCurrent = true;
  14. public GameObject Horizon;
  15. // Use this for initialization
  16. void OnEnable () {
  17. thisFog = GetComponent<FogVolume>();
  18. _FogVolumeData = thisFog._FogVolumeData;
  19. }
  20. // Update is called once per frame
  21. void Update()
  22. {
  23. // if (AutoAssignCameraCurrent)
  24. // GameCamera = Camera.current;
  25. if(Horizon)
  26. HeightThreshold = Horizon.transform.position.y;
  27. //if(!Application.isPlaying)
  28. // GameCamera = Camera.current;
  29. if (_FogVolumeData)
  30. GameCamera = _FogVolumeData.GameCamera;
  31. else
  32. GameCamera = Camera.main;
  33. if (GameCamera)
  34. {
  35. if (!Application.isPlaying)
  36. {
  37. if (Camera.current != null)
  38. CurrentHeight = Camera.current.gameObject.transform.position.y;
  39. }
  40. else
  41. CurrentHeight = GameCamera.gameObject.transform.position.y;
  42. if (HeightThreshold > CurrentHeight && Horizon != null)
  43. thisFog.DrawOrder = FogOrderCameraBelow;
  44. else
  45. thisFog.DrawOrder = FogOrderCameraAbove;
  46. }
  47. }
  48. }