You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

65 lines
1.7 KiB

using System;
namespace UnityEngine.Rendering
{
[ExecuteInEditMode]
internal class DisallowSmallMeshCulling : MonoBehaviour
{
private bool m_AppliedRecursively;
public bool m_applyToChildrenRecursively;
public bool applyToChildrenRecursively
{
get => m_applyToChildrenRecursively;
set
{
m_applyToChildrenRecursively = value;
OnDisable();
OnEnable();
}
}
private void OnEnable()
{
m_AppliedRecursively = applyToChildrenRecursively;
if (applyToChildrenRecursively)
AllowSmallMeshCullingRecursively(transform, false);
else
AllowSmallMeshCulling(transform, false);
}
private void OnDisable()
{
if (m_AppliedRecursively)
AllowSmallMeshCullingRecursively(transform, true);
else
AllowSmallMeshCulling(transform, true);
}
private static void AllowSmallMeshCulling(Transform transform, bool allow)
{
var renderer = transform.GetComponent<MeshRenderer>();
if (renderer)
renderer.smallMeshCulling = allow;
}
private static void AllowSmallMeshCullingRecursively(Transform transform, bool allow)
{
AllowSmallMeshCulling(transform, allow);
foreach (Transform child in transform)
{
if (!child.GetComponent<DisallowGPUDrivenRendering>())
AllowSmallMeshCullingRecursively(child, allow);
}
}
private void OnValidate()
{
OnDisable();
OnEnable();
}
}
}