GameObject Spawn(PoolObjectInformation PoolEntry, GameObject PrefabToSpawn, List <ISavable> SavablesInObject, Vector3 Position) { if (Dbug.Is(DebugMode.EXTENSIVE)) { Debug.Log("Spawning Object " + PoolEntry.ObjectReference.GetComponent <JustSaveRuntimeId>().GetSaveIdentifier()); } PrefabToSpawn.GetComponent <JustSaveRuntimeId>().Spawn(); PrefabToSpawn.transform.position = Position; PrefabToSpawn.SetActive(true); Pool.Add(PoolEntry); Pool.RemoveAt(0); //calling JSOnSpawned() on every Savable in the Prefab foreach (Savable mySavable in SavablesInObject) { mySavable.JSOnSpawned(); } if (NotifyToDespawn > 0 && GetPoolSize() - CurrentlyActiveObjects <= NotifyToDespawn) { foreach (ISavable ISavableComponent in Pool[NotifyToDespawn].SavablesInObject) { ISavableComponent.JSOnNeeded(); } } CurrentlyActiveObjects++; return(PrefabToSpawn); }
/// <summary> /// Despawns a Savable Object by given PoolObjectInformation /// </summary> /// <param name="PoolObject">The poolentry to use for despawning</param> public void Despawn(PoolObjectInformation PoolObject) { if (Dbug.Is(DebugMode.EXTENSIVE)) { Debug.Log("Despawning Object " + PoolObject.ObjectReference.GetComponent <JustSaveRuntimeId>().GetSaveIdentifier()); } PoolObject.ObjectReference.SetActive(false); PoolObject.SetSpawned(false); PoolObject.ObjectReference.transform.position = Vector3.zero; CurrentlyActiveObjects--; }