Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyCustomRenderer : MonoBehaviour
{
public Material MyUniqueMaterial;
public bool bool_Building_Material_1 = true;
public bool bool_Windows_Material_2 = true;
public bool bool_Grass_Material_3 = true;
public bool bool_Garage_Material_4 = true;
public bool bool_Water_Barrel_Material_5 = true;
public bool bool_Water_Tank_Material_6 = true;
public bool bool_Vegetation_Material_7 = true;
public bool bool_Solar_Panel_Material_8 = true;
public Camera MyCamera;
private Mesh MyMesh;
private Vector3 MyPosition;
private Quaternion MyRotation;
private MaterialPropertyBlock MyMaterialPropertyBlock;
// Start is called before the first frame update
void Start()
{
MyMesh = GetComponent<MeshFilter>().mesh;
MyPosition = transform.position;
MyRotation = transform.rotation;
MyMaterialPropertyBlock = new MaterialPropertyBlock();
}
// Update is called once per frame
void Update()
{
if (bool_Building_Material_1)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 0, MyMaterialPropertyBlock, true, true, true);
}
if (bool_Windows_Material_2)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 1, MyMaterialPropertyBlock, true, true, true);
}
if (bool_Grass_Material_3)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 2, MyMaterialPropertyBlock, true, true, true);
}
if (bool_Garage_Material_4)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 3, MyMaterialPropertyBlock, true, true, true);
}
if (bool_Water_Barrel_Material_5)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 4, MyMaterialPropertyBlock, true, true, true);
}
if (bool_Water_Tank_Material_6)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 5, MyMaterialPropertyBlock, true, true, true);
}
if (bool_Vegetation_Material_7)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 6, MyMaterialPropertyBlock, true, true, true);
}
if (bool_Solar_Panel_Material_8)
{
Graphics.DrawMesh(MyMesh, MyPosition, MyRotation, MyUniqueMaterial, 0, MyCamera, 7, MyMaterialPropertyBlock, true, true, true);
}
}
}
C'est grossier mais cela fait le taf.