/** * Copyright(c) Live2D Inc. All rights reserved. * * Use of this source code is governed by the Live2D Open Software license * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. */ using UnityEngine; namespace Live2D.Cubism.Core { /// /// Extensions for s. /// public static class ComponentExtensionMethods { /// /// Finds a relative to a . /// /// Component to base search on. /// Condition for including parents in search. /// The relative if found; otherwise. public static CubismModel FindCubismModel(this Component self, bool includeParents = false) { // Validate arguments. if (self == null) { return null; } var model = self.GetComponent(); // Return model if found. if (model != null) { return model; } // Recursively search in parents if requested. if (includeParents) { for (var parent = self.transform.parent; parent != null; parent = parent.parent) { model = parent.GetComponent(); if (model) { return model; } } } // Signal not found. return null; } } }