76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using MagicaCloth2;
|
|
using UnityEngine;
|
|
|
|
namespace Framework
|
|
{
|
|
public class ComponentCollector
|
|
{
|
|
public Transform[] Transforms;
|
|
public Renderer[] Renderers;
|
|
public Renderer FirstRenderer;
|
|
public BoxCollider[] BoxColliders;
|
|
public ParticleSystem[] ParticleSystems;
|
|
public MeshFilter[] MeshFilters;
|
|
public MeshFilter FirstMeshFilter;
|
|
public Animator FirstAnimator;
|
|
public Animator[] Animators;
|
|
public MagicaCloth[] MagicaCloths;
|
|
public MagicaCloth MagicaClothFirst;
|
|
|
|
|
|
public ComponentCollector(GameObject go)
|
|
{
|
|
Transforms = CollectAll<Transform>(go);
|
|
Renderers = CollectAll<Renderer>(go);
|
|
BoxColliders = CollectAll<BoxCollider>(go);
|
|
ParticleSystems = CollectAll<ParticleSystem>(go);
|
|
MeshFilters = CollectAll<MeshFilter>(go);
|
|
Animators = CollectAll<Animator>(go);
|
|
MagicaCloths = CollectAll<MagicaCloth>(go);
|
|
|
|
if (Renderers?.Length > 0)
|
|
{
|
|
FirstRenderer = Renderers?[0];
|
|
}
|
|
|
|
if (MeshFilters?.Length > 0)
|
|
{
|
|
FirstMeshFilter = MeshFilters?[0];
|
|
}
|
|
|
|
if (Animators?.Length > 0)
|
|
{
|
|
FirstAnimator = Animators?[0];
|
|
}
|
|
|
|
if (MagicaCloths?.Length > 0)
|
|
{
|
|
MagicaClothFirst = MagicaCloths[0];
|
|
}
|
|
}
|
|
|
|
|
|
private void Collect<T>(Transform t, ref List<T> components, bool recrusive)
|
|
{
|
|
var c = t.GetComponent<T>();
|
|
if (c != null && !c.Equals(null))
|
|
{
|
|
components.Add(c);
|
|
}
|
|
|
|
if (recrusive)
|
|
{
|
|
for (int i = 0; i < t.childCount; i++)
|
|
{
|
|
Collect(t.GetChild(i), ref components, recrusive);
|
|
}
|
|
}
|
|
}
|
|
|
|
private T[] CollectAll<T>(GameObject go)
|
|
{
|
|
return go.GetComponentsInChildren<T>(true);
|
|
}
|
|
}
|
|
} |