56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.ThoMagic.Renderer
|
|
{
|
|
public class RendererUtility
|
|
{
|
|
public static GameObject GetPrototypeToRender(DetailPrototype prototype) => prototype.prototype == null ? null :
|
|
prototype.prototype.transform.root.gameObject;
|
|
|
|
public static bool SupportsProceduralInstancing(GameObject gameObject)
|
|
{
|
|
foreach (var componentsInChild in gameObject.GetComponentsInChildren<MeshRenderer>())
|
|
{
|
|
foreach (var sharedMaterial in componentsInChild.sharedMaterials)
|
|
{
|
|
if (sharedMaterial != null && sharedMaterial.shader != null && !RendererUtility.SupportsProceduralInstancing(sharedMaterial))
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static bool SupportsProceduralInstancing(Material material)
|
|
{
|
|
if (material == null)
|
|
throw new ArgumentNullException(nameof(material));
|
|
if (material.shader == null)
|
|
throw new ArgumentNullException("material.shader");
|
|
return true;
|
|
}
|
|
|
|
public static bool IsSupportedByUnity(DetailPrototype prototype) => !prototype.usePrototypeMesh || prototype.prototype == null || prototype.prototype.GetComponent<LODGroup>() == null;
|
|
|
|
public static GameObject GetSupportedPlaceholder(DetailPrototype prototype) => IsSupportedByUnity(prototype) ? prototype.prototype : GetSupportedPlaceholder(prototype.prototype);
|
|
|
|
public static GameObject GetSupportedPlaceholder(GameObject prototype)
|
|
{
|
|
if (prototype == null)
|
|
return prototype;
|
|
LODGroup component = prototype.GetComponent<LODGroup>();
|
|
if (component == null)
|
|
return prototype;
|
|
foreach (LOD loD in component.GetLODs())
|
|
{
|
|
foreach (UnityEngine.Renderer renderer in loD.renderers)
|
|
{
|
|
if (renderer != null)
|
|
return renderer.gameObject;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|