VolumetricFogSubVolume.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace VolumetricFogAndMist2 {
  4. public class VolumetricFogSubVolume : MonoBehaviour {
  5. public VolumetricFogProfile profile;
  6. public float fadeDistance = 1f;
  7. public static List<VolumetricFogSubVolume> subVolumes = new List<VolumetricFogSubVolume>();
  8. void OnDrawGizmos() {
  9. Gizmos.color = new Color(1, 1, 1, 0.35f);
  10. Gizmos.DrawWireCube(transform.position, transform.lossyScale);
  11. }
  12. void OnEnable() {
  13. if (!subVolumes.Contains(this)) {
  14. subVolumes.Add(this);
  15. }
  16. }
  17. void OnDisable() {
  18. if (subVolumes.Contains(this)) {
  19. subVolumes.Remove(this);
  20. }
  21. }
  22. public Bounds GetBounds() {
  23. return new Bounds(transform.position, transform.lossyScale);
  24. }
  25. public void SetBounds(Bounds bounds) {
  26. Transform parent = transform.parent;
  27. Vector3 scale = bounds.size;
  28. if (parent != null) {
  29. Vector3 scaleFactor = transform.parent.lossyScale;
  30. scale.x /= scaleFactor.x;
  31. scale.y /= scaleFactor.y;
  32. scale.z /= scaleFactor.z;
  33. }
  34. transform.localScale = scale;
  35. transform.position = bounds.center;
  36. }
  37. }
  38. }