summaryrefslogtreecommitdiff
path: root/DeepSky.Haze/DS_HazeZone.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:00:58 +0800
committerchai <215380520@qq.com>2024-03-13 11:00:58 +0800
commit6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch)
treeb38119d2acf0a982cb67e381f146924b9bfc3b3f /DeepSky.Haze/DS_HazeZone.cs
+init
Diffstat (limited to 'DeepSky.Haze/DS_HazeZone.cs')
-rw-r--r--DeepSky.Haze/DS_HazeZone.cs105
1 files changed, 105 insertions, 0 deletions
diff --git a/DeepSky.Haze/DS_HazeZone.cs b/DeepSky.Haze/DS_HazeZone.cs
new file mode 100644
index 0000000..b4ffabb
--- /dev/null
+++ b/DeepSky.Haze/DS_HazeZone.cs
@@ -0,0 +1,105 @@
+using UnityEngine;
+
+namespace DeepSky.Haze;
+
+[ExecuteInEditMode]
+[AddComponentMenu("DeepSky Haze/Zone", 52)]
+public class DS_HazeZone : MonoBehaviour
+{
+ [SerializeField]
+ private DS_HazeContext m_Context = new DS_HazeContext();
+
+ [SerializeField]
+ [Range(0f, 250f)]
+ private int m_Priority;
+
+ [SerializeField]
+ [Range(0.001f, 1f)]
+ private float m_BlendRange = 0.1f;
+
+ private Bounds m_AABB;
+
+ private float m_BlendRangeInverse;
+
+ public DS_HazeContext Context => m_Context;
+
+ public int Priority
+ {
+ get
+ {
+ return m_Priority;
+ }
+ set
+ {
+ m_Priority = ((value > 0) ? value : 0);
+ }
+ }
+
+ public float BlendRange
+ {
+ get
+ {
+ return m_BlendRange;
+ }
+ set
+ {
+ m_BlendRange = Mathf.Clamp01(value);
+ }
+ }
+
+ private void Setup()
+ {
+ m_AABB = new Bounds(Vector3.zero, base.transform.localScale);
+ m_BlendRangeInverse = 1f / Mathf.Max(Mathf.Min(m_AABB.extents.x, m_AABB.extents.y, m_AABB.extents.z) * m_BlendRange, Mathf.Epsilon);
+ }
+
+ private void Start()
+ {
+ Setup();
+ }
+
+ private void OnValidate()
+ {
+ Setup();
+ }
+
+ public bool Contains(Vector3 position)
+ {
+ if (base.transform.hasChanged)
+ {
+ Setup();
+ }
+ Vector3 point = base.transform.InverseTransformPoint(position);
+ point.Scale(base.transform.localScale);
+ return m_AABB.Contains(point);
+ }
+
+ public float GetBlendWeight(Vector3 position)
+ {
+ Vector3 vector = base.transform.InverseTransformPoint(position);
+ vector.Scale(base.transform.localScale);
+ float num = Mathf.Abs(m_AABB.extents.x - Mathf.Abs(vector.x));
+ float num2 = Mathf.Abs(m_AABB.extents.y - Mathf.Abs(vector.y));
+ float num3 = Mathf.Abs(m_AABB.extents.z - Mathf.Abs(vector.z));
+ float num4 = Mathf.Min(num, num2, num3);
+ return Mathf.Clamp01(num4 * m_BlendRangeInverse);
+ }
+
+ public static bool operator >(DS_HazeZone c1, DS_HazeZone c2)
+ {
+ if (c1.m_Priority == c2.m_Priority)
+ {
+ return (Vector3.Dot(c1.m_AABB.extents, c1.m_AABB.extents) > Vector3.Dot(c2.m_AABB.extents, c2.m_AABB.extents)) ? true : false;
+ }
+ return (c1.m_Priority > c2.m_Priority) ? true : false;
+ }
+
+ public static bool operator <(DS_HazeZone c1, DS_HazeZone c2)
+ {
+ if (c1.m_Priority == c2.m_Priority)
+ {
+ return (Vector3.Dot(c1.m_AABB.extents, c1.m_AABB.extents) < Vector3.Dot(c2.m_AABB.extents, c2.m_AABB.extents)) ? true : false;
+ }
+ return (c1.m_Priority < c2.m_Priority) ? true : false;
+ }
+}