Пример #1
0
    public void ReleaseObject(string path, GameObject prefab)
    {
        PooleableObject prefabPooleable = prefab.GetComponent <PooleableObject>();

        if (prefabPooleable == null)
        {
            prefab.AddComponent <PooleableObject>();
            prefabPooleable      = prefab.GetComponent <PooleableObject>();
            prefabPooleable.path = path;
        }
        prefab.gameObject.SetActive(false);

        if (!objectsPool.ContainsKey(path))
        {
            objectsPool.Add(path, new List <GameObject>());
        }
        prefab.transform.SetParent(this.transform);
        objectsPool[path].Add(prefab);
    }
Пример #2
0
 private void InstantiateObject(string path)
 {
     if (ResourcesManager.Instance.GetGameObject(path) != null)
     {
         GameObject instance = Instantiate(ResourcesManager.Instance.GetGameObject(path), transform);
         if (instance != null)
         {
             PooleableObject poolable = instance.GetComponent <PooleableObject>();
             if (poolable == null)
             {
                 poolable = instance.AddComponent <PooleableObject>();
             }
             poolable.path = path;
             instance.gameObject.SetActive(false);
             instance.transform.position = this.transform.position;
             objectsPool[path].Add(instance);
         }
     }
     else
     {
         Debug.LogWarning("object in path " + path + " doesnt exist");
     }
 }