EnviroEffectRemovalZone.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Enviro
  5. {
  6. [ExecuteInEditMode]
  7. [AddComponentMenu("Enviro 3/Effect Removal Zone")]
  8. public class EnviroEffectRemovalZone : MonoBehaviour
  9. {
  10. [Range(-2f, 0f)]
  11. public float density = 0.0f;
  12. public float radius = 1.0f;
  13. public float stretch = 2.0f;
  14. [Range(0, 1)]
  15. public float feather = 0.7f;
  16. private bool addedToMgr = false;
  17. void OnEnable()
  18. {
  19. AddToZoneToManager();
  20. }
  21. void OnDisable()
  22. {
  23. RemoveZoneFromManager();
  24. }
  25. void OnDestroy()
  26. {
  27. RemoveZoneFromManager();
  28. }
  29. void AddToZoneToManager()
  30. {
  31. if (!addedToMgr)
  32. addedToMgr = EnviroManager.instance.AddRemovalZone(this);
  33. }
  34. void RemoveZoneFromManager()
  35. {
  36. if (addedToMgr)
  37. EnviroManager.instance.RemoveRemovaleZone(this);
  38. addedToMgr = false;
  39. }
  40. void OnDrawGizmosSelected()
  41. {
  42. Matrix4x4 m = Matrix4x4.identity;
  43. Transform t = transform;
  44. m.SetTRS(t.position, t.rotation, new Vector3(1.0f, stretch, 1.0f));
  45. Gizmos.matrix = m;
  46. Gizmos.DrawWireSphere(Vector3.zero, radius);
  47. }
  48. }
  49. }