iamabigartist_OurForests/OF test0/Assets/Projects/CPUVoxelTest/Scripts/Tests/ManyCubeRendering.cs
using UnityEngine;
namespace CPUVoxelTest.Scripts.Tests
{
    
    /// <summary>
    /// Test the renderer performance when rendering many cubes
    /// </summary>
    public class ManyCubeRendering : MonoBehaviour
    {
        [SerializeField]
        int cube_count;
        [Range( 0, 1f )]
        public float rendering_ratio;
        public GameObject m_cube_prefab;

        void GenerateAllCube()
        {
            for (int i = 0; i < cube_count; i++)
            {
                Instantiate( m_cube_prefab,
                    new Vector3(
                        Random.Range( 0, 10f ),
                        Random.Range( 0, 10f ),
                        Random.Range( 0, 10f ) ),
                    Quaternion.identity, transform );
            }
        }

        void RefreshAllCubeRenderer()
        {
            var cube_renderer = transform.GetComponentsInChildren<MeshRenderer>();
            for (int i = 0; i < cube_renderer.Length; i++)
            {
                cube_renderer[i].enabled = Random.Range( 0f, 1f ) < rendering_ratio;
            }
        }

        void Start()
        {
            GenerateAllCube();
        }

        void OnValidate()
        {
            RefreshAllCubeRenderer();
        }

    }
}
