A game about forced loneliness, made by TACStudios
1using System;
2
3namespace UnityEngine.Rendering
4{
5 [ExecuteInEditMode]
6 internal class DisallowSmallMeshCulling : MonoBehaviour
7 {
8 private bool m_AppliedRecursively;
9 public bool m_applyToChildrenRecursively;
10
11 public bool applyToChildrenRecursively
12 {
13 get => m_applyToChildrenRecursively;
14 set
15 {
16 m_applyToChildrenRecursively = value;
17 OnDisable();
18 OnEnable();
19 }
20 }
21
22 private void OnEnable()
23 {
24 m_AppliedRecursively = applyToChildrenRecursively;
25
26 if (applyToChildrenRecursively)
27 AllowSmallMeshCullingRecursively(transform, false);
28 else
29 AllowSmallMeshCulling(transform, false);
30 }
31
32 private void OnDisable()
33 {
34 if (m_AppliedRecursively)
35 AllowSmallMeshCullingRecursively(transform, true);
36 else
37 AllowSmallMeshCulling(transform, true);
38 }
39
40 private static void AllowSmallMeshCulling(Transform transform, bool allow)
41 {
42 var renderer = transform.GetComponent<MeshRenderer>();
43
44 if (renderer)
45 renderer.smallMeshCulling = allow;
46 }
47
48 private static void AllowSmallMeshCullingRecursively(Transform transform, bool allow)
49 {
50 AllowSmallMeshCulling(transform, allow);
51
52 foreach (Transform child in transform)
53 {
54 if (!child.GetComponent<DisallowGPUDrivenRendering>())
55 AllowSmallMeshCullingRecursively(child, allow);
56 }
57 }
58
59 private void OnValidate()
60 {
61 OnDisable();
62 OnEnable();
63 }
64 }
65}