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(go); Renderers = CollectAll(go); BoxColliders = CollectAll(go); ParticleSystems = CollectAll(go); MeshFilters = CollectAll(go); Animators = CollectAll(go); MagicaCloths = CollectAll(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(Transform t, ref List components, bool recrusive) { var c = t.GetComponent(); 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(GameObject go) { return go.GetComponentsInChildren(true); } } }