Add files via upload

Some first day fug fixes.
This commit is contained in:
Geri 2021-01-09 01:57:59 +01:00 committed by GitHub
parent 7046716893
commit a29bc6aba4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 123 additions and 10 deletions

View file

@ -11,13 +11,27 @@ public static class Pooler{
static Dictionary<string, Pool.PoolPrefab> poolDictionary;
static Scene poolScene;
/// <summary>Generate a scene with the objects of the pools in it
/// <para>If this isn't called, the pooler won't work</para>
/// </summary>
public static void CreatePools(Pool pool){
poolDictionary = new Dictionary<string, Pool.PoolPrefab>();
poolScene = SceneManager.CreateScene("PoolScene");
if(pool == null){
Debug.LogWarning("You have to provide a pool.");
return;
}
foreach(Pool.PoolPrefab p in pool.pools){
poolDictionary = new Dictionary<string, Pool.PoolPrefab>();
if (SceneManager.GetSceneByName("PoolScene").IsValid()){
poolScene = SceneManager.GetSceneByName("PoolScene");
}else{
poolScene = SceneManager.CreateScene("PoolScene");
}
foreach (Pool.PoolPrefab p in pool.pools){
if (!p.undetermined){
p.determinedPool = new Queue<GameObject>();
if(p.determinedPool == null){
p.determinedPool = new Queue<GameObject>();
}
for (int i = 0; i < p.size; i++){
GameObject obj = Object.Instantiate(p.prefab);
obj.SetActive(false);
@ -26,19 +40,35 @@ public static class Pooler{
p.determinedPool.Enqueue(obj);
}
}else{
p.undeterminedPool = new List<GameObject>();
if(p.undeterminedPool == null){
p.undeterminedPool = new List<GameObject>();
}
}
poolDictionary.Add(p.tag, p);
}
}
/// <summary>Generate a scene with the objects of the pools in it
/// <para>If this isn't called, the pooler won't work</para>
/// </summary>
public static void CreatePools(Pool[] pools){
if (pools == null){
Debug.LogWarning("You have to provide a pool.");
return;
}
poolDictionary = new Dictionary<string, Pool.PoolPrefab>();
poolScene = SceneManager.CreateScene("PoolScene");
if (SceneManager.GetSceneByName("PoolScene").IsValid()){
poolScene = SceneManager.GetSceneByName("PoolScene");
}else{
poolScene = SceneManager.CreateScene("PoolScene");
}
for (int i = 0; i < pools.Length; i++){
foreach (Pool.PoolPrefab p in pools[i].pools){
if (!p.undetermined){
p.determinedPool = new Queue<GameObject>();
if (p.determinedPool == null){
p.determinedPool = new Queue<GameObject>();
}
for (int j = 0; j < p.size; j++){
GameObject obj = Object.Instantiate(p.prefab);
obj.SetActive(false);
@ -47,12 +77,16 @@ public static class Pooler{
p.determinedPool.Enqueue(obj);
}
}else{
p.undeterminedPool = new List<GameObject>();
if (p.undeterminedPool == null){
p.undeterminedPool = new List<GameObject>();
}
}
poolDictionary.Add(p.tag, p);
}
}
}
/// <summary>Destroy an object and return it to the pool scene
/// </summary>
public static void Destroy(GameObject gameObject){
PoolChecker poolChecker = gameObject.GetComponent<PoolChecker>();
if (poolChecker == null){
@ -74,6 +108,9 @@ public static class Pooler{
}
}
/// <summary>Spawn an object into a specific position
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
@ -111,6 +148,9 @@ public static class Pooler{
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position and parent
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position, Transform parent){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
@ -149,6 +189,9 @@ public static class Pooler{
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position, parent and set if it's in world space or not
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position, Transform parent, bool instantiateInWorldSpace){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
@ -194,6 +237,9 @@ public static class Pooler{
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position and rotation
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
@ -231,6 +277,9 @@ public static class Pooler{
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position, rotation and parent
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation, Transform parent){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");
@ -269,6 +318,9 @@ public static class Pooler{
}
return objectToSpawn;
}
/// <summary>Spawn an object into a specific position, rotation, parent and set if it's in world space or not
/// <para>The CreatePools function must have been called before.</para>
/// </summary>
public static GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation, Transform parent, bool instantiateInWorldSpace){
if (!poolDictionary.ContainsKey(tag)){
Debug.Log("Pool with tag " + tag + " doesn't exist.");