// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using UnityEngine; namespace Microsoft.MixedReality.Toolkit.Utilities { /// /// Component which can be used to render an outline around a hierarchy of mesh renderers using /// the component. /// [AddComponentMenu("Scripts/MRTK/Core/MeshOutlineHierarchy")] public class MeshOutlineHierarchy : BaseMeshOutline { private MeshOutline[] meshOutlines = null; #region MonoBehaviour Implementation /// /// Creates a component on each child MeshRenderer. /// private void Awake() { MeshRenderer[] meshRenderers = GetComponentsInChildren(); meshOutlines = new MeshOutline[meshRenderers.Length]; for (int i = 0; i < meshRenderers.Length; ++i) { var meshOutline = meshRenderers[i].gameObject.AddComponent(); meshOutline.OutlineMaterial = outlineMaterial; meshOutline.OutlineWidth = outlineWidth; meshOutlines[i] = meshOutline; } } /// /// Removes any components this component has created. /// private void OnDestroy() { foreach (var meshOutline in meshOutlines) { Destroy(meshOutline); } } #endregion MonoBehaviour Implementation #region BaseMeshOutline Implementation /// /// Forwards the outlineMaterial to all children s. /// protected override void ApplyOutlineMaterial() { if (meshOutlines != null) { foreach (var meshOutline in meshOutlines) { if (meshOutline != null) { meshOutline.OutlineMaterial = outlineMaterial; } } } } /// /// Forwards the outlineWidth to all children s. /// protected override void ApplyOutlineWidth() { if (meshOutlines != null) { foreach (var meshOutline in meshOutlines) { if (meshOutline != null) { meshOutline.OutlineWidth = outlineWidth; } } } } #endregion BaseMeshOutline Implementation } }