-
Notifications
You must be signed in to change notification settings - Fork 0
Renderer Extensions
This utility library, part of the RendererExtensions namespace, provides extension methods for Unity's Renderer class, offering additional functionality for visibility checks, obtaining bounds, and accessing materials.
Checks if the renderer is visible from the specified camera.
// Example usage
Renderer myRenderer = /* Instantiate or reference a Renderer */;
Camera mainCamera = Camera.main; // or reference to any other camera
bool isVisible = myRenderer.IsVisible(mainCamera);
Debug.Log($"Is the renderer visible from the camera? {isVisible}");Parameters:
-
renderer(Renderer): The renderer to check. -
camera(Camera): The camera to check visibility from.
Returns:
- bool: True if the renderer is visible from the camera, false otherwise.
Gets the bounds of the renderer. If includeChildren is true, the bounds encapsulate the bounds of child renderers.
// Example usage
Renderer myRenderer = /* Instantiate or reference a Renderer */;
bool includeChildren = true;
Bounds bounds = myRenderer.GetBounds(includeChildren);
Debug.Log($"Bounds of the renderer: {bounds}");Parameters:
-
renderer(Renderer): The renderer to get the bounds from. -
includeChildren(bool): Whether to include the bounds of child renderers. Default is true.
Returns:
- Bounds: The bounds of the renderer. If
includeChildrenis true, the bounds encapsulate the bounds of child renderers.
Gets the material at the specified index.
// Example usage
Renderer myRenderer = /* Instantiate or reference a Renderer */;
int materialIndex = 0; // Index of the material to get
Material material = myRenderer.GetMaterial(materialIndex);
Debug.Log($"Material at index {materialIndex}: {material}");Parameters:
-
renderer(Renderer): The renderer to get the material from. -
materialIndex(int): The index of the material to get.
Returns:
- Material: The material at the specified index, or null if the index is out of range.
Enables ZWrite for materials in this Renderer that have a '_Color' property. This allows the materials to write to the Z buffer, affecting subsequent rendering, especially useful for correct layering of transparent objects.
Renderer myRenderer = GetComponent<Renderer>();
myRenderer.EnableZWrite();Parameters:
-
renderer: The Renderer instance to enable ZWrite.
Disables ZWrite for materials in this Renderer that have a '_Color' property. This prevents the materials from writing to the Z buffer, which can be desirable in some cases to avoid occlusion of subsequent rendering, especially for semi-transparent or layered objects.
Renderer myRenderer = GetComponent<Renderer>();
myRenderer.DisableZWrite();Parameters:
-
renderer: The Renderer instance to disable ZWrite.