Ejemplo n.º 1
0
    public static Dictionary <int, GameObject> FindIndexedComponents(Transform root)
    {
        Dictionary <int, GameObject> allComponents = new Dictionary <int, GameObject>();

        EB.Collections.Queue <Transform> queue = new EB.Collections.Queue <Transform>(16);
        queue.Enqueue(root);
        while (queue.Count > 0)
        {
            Transform            it      = queue.Dequeue();
            IndexedZoneComponent indexer = it.GetComponent <IndexedZoneComponent>();

            if (indexer != null)
            {
                allComponents.Add(indexer.Index, indexer.gameObject);
            }

            int childCount = it.childCount;
            for (int i = 0; i < childCount; ++i)
            {
                queue.Enqueue(it.GetChild(i));
            }
        }

        return(allComponents);
    }
Ejemplo n.º 2
0
    public T FindIndexedComponent <T>(int index) where T : Component
    {
        if (_indexedComponents == null)
        {
            _indexedComponents = IndexedZoneComponent.FindIndexedComponents(transform);
        }

        if (_indexedComponents.ContainsKey(index))
        {
            return(_indexedComponents[index].GetComponent <T>());
        }
        else
        {
            return(null);
        }
    }