From 6f3754b37b92ca08771b2cad6e2d1f7587c4d73f Mon Sep 17 00:00:00 2001 From: Mike Geig Date: Mon, 31 Jul 2017 16:03:02 -0400 Subject: [PATCH 1/4] Added UI toggle for child colliders --- PostProcessing/Editor/PostProcessVolumeEditor.cs | 9 +++++++-- PostProcessing/Runtime/PostProcessVolume.cs | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/PostProcessing/Editor/PostProcessVolumeEditor.cs b/PostProcessing/Editor/PostProcessVolumeEditor.cs index b02e75fd..80139138 100644 --- a/PostProcessing/Editor/PostProcessVolumeEditor.cs +++ b/PostProcessing/Editor/PostProcessVolumeEditor.cs @@ -11,6 +11,7 @@ public sealed class PostProcessVolumeEditor : BaseEditor SerializedProperty m_IsGlobal; SerializedProperty m_BlendRadius; + SerializedProperty m_UseChildColliders; SerializedProperty m_Weight; SerializedProperty m_Priority; @@ -22,6 +23,7 @@ void OnEnable() m_IsGlobal = FindProperty(x => x.isGlobal); m_BlendRadius = FindProperty(x => x.blendDistance); + m_UseChildColliders = FindProperty (x => x.useChildColliders); m_Weight = FindProperty(x => x.weight); m_Priority = FindProperty(x => x.priority); @@ -48,8 +50,11 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(m_IsGlobal); - if (!m_IsGlobal.boolValue) // Blend radius is not needed for global volumes - EditorGUILayout.PropertyField(m_BlendRadius); + if (!m_IsGlobal.boolValue) + { // Blend radius is not needed for global volumes + EditorGUILayout.PropertyField (m_BlendRadius); + EditorGUILayout.PropertyField (m_UseChildColliders); + } EditorGUILayout.PropertyField(m_Weight); EditorGUILayout.PropertyField(m_Priority); diff --git a/PostProcessing/Runtime/PostProcessVolume.cs b/PostProcessing/Runtime/PostProcessVolume.cs index 83fc2bc5..97b875c8 100644 --- a/PostProcessing/Runtime/PostProcessVolume.cs +++ b/PostProcessing/Runtime/PostProcessVolume.cs @@ -65,6 +65,9 @@ public sealed class PostProcessVolume : MonoBehaviour [Min(0f), Tooltip("Outer distance to start blending from. A value of 0 means no blending and the volume overrides will be applied immediatly upon entry.")] public float blendDistance = 0f; + [Tooltip("Should volumes be calculated based on colliders from children objects as well?")] + public bool useChildColliders = false; + [Range(0f, 1f), Tooltip("Total weight of this volume in the scene. 0 means it won't do anything, 1 means full effect.")] public float weight = 1f; @@ -156,7 +159,11 @@ void Update() void OnDrawGizmos() { var colliders = m_TempColliders; - GetComponents(colliders); + + if (useChildColliders) + GetComponentsInChildren (colliders); + else + GetComponents(colliders); if (isGlobal || colliders == null) return; From 83c4fda2fc8fc13ec3b886fab11fe755c4e438b9 Mon Sep 17 00:00:00 2001 From: Mike Geig Date: Mon, 31 Jul 2017 16:25:46 -0400 Subject: [PATCH 2/4] Worked through box collider gizmo --- PostProcessing/Runtime/PostProcessVolume.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/PostProcessing/Runtime/PostProcessVolume.cs b/PostProcessing/Runtime/PostProcessVolume.cs index 97b875c8..ff571fec 100644 --- a/PostProcessing/Runtime/PostProcessVolume.cs +++ b/PostProcessing/Runtime/PostProcessVolume.cs @@ -178,9 +178,9 @@ void OnDrawGizmos() } #endif - var scale = transform.localScale; - var invScale = new Vector3(1f / scale.x, 1f / scale.y, 1f / scale.z); - Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, scale); + // var scale = transform.localScale; + // var invScale = new Vector3(1f / scale.x, 1f / scale.y, 1f / scale.z); + //Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, scale); // Draw a separate gizmo for each collider foreach (var collider in colliders) @@ -188,6 +188,11 @@ void OnDrawGizmos() if (!collider.enabled) continue; + var pos = collider.transform.position; + var lossyScale = collider.transform.lossyScale; + var scale = transform.localScale; + var invScale = new Vector3(1f / scale.x, 1f / scale.y, 1f / scale.z); + // We'll just use scaling as an approximation for volume skin. It's far from being // correct (and is completely wrong in some cases). Ultimately we'd use a distance // field or at least a tesselate + push modifier on the collider's mesh to get a @@ -200,8 +205,9 @@ void OnDrawGizmos() if (type == typeof(BoxCollider)) { var c = (BoxCollider)collider; - Gizmos.DrawCube(c.center, c.size); - Gizmos.DrawWireCube(c.center, c.size + invScale * blendDistance * 4f); + + Gizmos.DrawCube(pos + Vector3.Scale(c.center, scale), Vector3.Scale(lossyScale, c.size)); + // Gizmos.DrawWireCube(c.center, c.size + invScale * blendDistance * 4f); } else if (type == typeof(SphereCollider)) { From f5b1e27cdad413655137f8b95ec14aec7901cc6b Mon Sep 17 00:00:00 2001 From: Mike Geig Date: Mon, 31 Jul 2017 16:32:12 -0400 Subject: [PATCH 3/4] Refactored gizmo code and implemented for the different colliders --- PostProcessing/Runtime/PostProcessVolume.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/PostProcessing/Runtime/PostProcessVolume.cs b/PostProcessing/Runtime/PostProcessVolume.cs index ff571fec..e9172140 100644 --- a/PostProcessing/Runtime/PostProcessVolume.cs +++ b/PostProcessing/Runtime/PostProcessVolume.cs @@ -178,20 +178,15 @@ void OnDrawGizmos() } #endif - // var scale = transform.localScale; - // var invScale = new Vector3(1f / scale.x, 1f / scale.y, 1f / scale.z); - //Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, scale); - // Draw a separate gizmo for each collider foreach (var collider in colliders) { if (!collider.enabled) continue; - var pos = collider.transform.position; - var lossyScale = collider.transform.lossyScale; - var scale = transform.localScale; + var scale = collider.transform.lossyScale; var invScale = new Vector3(1f / scale.x, 1f / scale.y, 1f / scale.z); + Gizmos.matrix = Matrix4x4.TRS(collider.transform.position, collider.transform.rotation, scale); // We'll just use scaling as an approximation for volume skin. It's far from being // correct (and is completely wrong in some cases). Ultimately we'd use a distance @@ -206,8 +201,8 @@ void OnDrawGizmos() { var c = (BoxCollider)collider; - Gizmos.DrawCube(pos + Vector3.Scale(c.center, scale), Vector3.Scale(lossyScale, c.size)); - // Gizmos.DrawWireCube(c.center, c.size + invScale * blendDistance * 4f); + Gizmos.DrawCube(c.center, c.size); + Gizmos.DrawWireCube(c.center, c.size + invScale * blendDistance * 4f); } else if (type == typeof(SphereCollider)) { From 23a66c77076d1a11546e6cb10c3026f699846d1d Mon Sep 17 00:00:00 2001 From: Mike Geig Date: Mon, 31 Jul 2017 17:12:52 -0400 Subject: [PATCH 4/4] Added child colliders functionality code to process manager --- PostProcessing/Runtime/PostProcessManager.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/PostProcessing/Runtime/PostProcessManager.cs b/PostProcessing/Runtime/PostProcessManager.cs index 53777c41..718fdb2e 100644 --- a/PostProcessing/Runtime/PostProcessManager.cs +++ b/PostProcessing/Runtime/PostProcessManager.cs @@ -130,7 +130,12 @@ public void GetActiveVolumes(PostProcessLayer layer, List res // If volume isn't global and has no collider, skip it as it's useless var colliders = m_TempColliders; - volume.GetComponents(colliders); + + if (volume.useChildColliders) + volume.GetComponentsInChildren (colliders); + else + volume.GetComponents(colliders); + if (colliders.Count == 0) continue; @@ -322,8 +327,13 @@ internal void UpdateSettings(PostProcessLayer postProcessLayer) // If volume isn't global and has no collider, skip it as it's useless var colliders = m_TempColliders; - volume.GetComponents(colliders); - if (colliders.Count == 0) + + if (volume.useChildColliders) + volume.GetComponentsInChildren (colliders); + else + volume.GetComponents(colliders); + + if (colliders.Count == 0) continue; // Find closest distance to volume, 0 means it's inside it