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/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 diff --git a/PostProcessing/Runtime/PostProcessVolume.cs b/PostProcessing/Runtime/PostProcessVolume.cs index 83fc2bc5..e9172140 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; @@ -171,16 +178,16 @@ 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 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 // field or at least a tesselate + push modifier on the collider's mesh to get a @@ -193,8 +200,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(c.center, c.size); + Gizmos.DrawWireCube(c.center, c.size + invScale * blendDistance * 4f); } else if (type == typeof(SphereCollider)) {