/**
* 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 System.Collections.Generic;
using UnityEngine;
namespace Live2D.Cubism.Framework
{
///
/// Extensions for s.
///
public static class ComponentExtensionMethods
{
///
/// Gets components for each item of a sequence and flattens the resulting sequences into one sequence.
///
/// Component type to find.
/// Array to query.
/// Matches.
public static T[] GetComponentsMany(this Component[] self) where T : Component
{
var components = new List();
for (var i = 0; i < self.Length; ++i)
{
var range = self[i].GetComponents();
// Skip empty ranges.
if (range == null || range.Length == 0)
{
continue;
}
components.AddRange(range);
}
return components.ToArray();
}
///
/// Adds a component to multiple objects.
///
/// Component type to add.
/// Array of objects.
/// Added components.
public static T[] AddComponentEach(this Component[] self) where T : Component
{
var components = new T[self.Length];
for (var i = 0; i < self.Length; ++i)
{
components[i] = self[i].gameObject.AddComponent();
}
return components;
}
}
}