Ejemplo n.º 1
0
    public void InitPool(Action <GameObject> ResetAction = null)
    {
        if (inited)
        {
            return;
        }
        inited = true;

        this.m_objectStack   = new Dictionary <string, Stack <GameObject> >();
        this.gameObjectToKey = new Dictionary <GameObject, string>();
        this.m_resetAction   = ResetAction;
        string path = PrefabUtils.GetPrefabPath(prefabType);

        if (string.IsNullOrEmpty(path))
        {
            print("pool path is null. " + prefabType);
            return;
        }

        GameObject[] gos = Resources.LoadAll <GameObject>(path);
        foreach (GameObject go in gos)
        {
            Stack <GameObject> stack = new Stack <GameObject>();
            int count = GetPreloadAmount(go.name);
            for (int i = 0; i < count; i++)
            {
                GameObject child = PrefabUtils.AddChild(this.gameObject, go);
                child.SetActive(false);
                child.name  = go.name;
                child.layer = go.layer;
                stack.Push(child);
                gameObjectToKey.Add(child, go.name);
            }
            m_objectStack.Add(go.name, stack);
        }
    }