From 2bf8fdff2cfc174fd9e1ada5ce61565aaf47c0b8 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Fri, 10 May 2019 15:03:53 -0700 Subject: [PATCH] Added SetRedneringActive game object extension --- .../Extensions/GameObjectExtensions.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs b/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs index a80c18f00..c90071a15 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; namespace XRTK.Extensions { @@ -133,5 +134,38 @@ public static void ForEachComponent(this GameObject gameObject, Action act action(i); } } + + /// + /// Sets the s and optionally s in this to the provided state. + /// + /// If the GameObject or it's children are inactive, they will be set active, but the GameObjects will not be set inactive. + /// + /// + /// + public static void SetRenderingActive(this GameObject gameObject, bool isActive, bool includeColliders = true) + { + if (isActive) + { + gameObject.SetActive(true); + } + + foreach (var renderer in gameObject.GetComponentsInChildren()) + { + renderer.enabled = isActive; + } + + foreach (var graphic in gameObject.GetComponentsInChildren()) + { + graphic.enabled = isActive; + } + + if (includeColliders) + { + foreach (var collider in gameObject.GetComponentsInChildren()) + { + collider.enabled = isActive; + } + } + } } }