public Factory(RecycleObject prefab, int defaultPoolSize = 5) { this.prefab = prefab; this.defaultPoolSize = defaultPoolSize; Debug.Assert(this.prefab != null, "Prefba is null"); }
public PoolFactory(RecycleObject prefab, int defaultPoolSize = 5) { this._prefab = prefab; this._defaultPoolSize = defaultPoolSize; Debug.Assert(this._prefab != null, "Prefab is null!"); }
void loadImage(RecycleObject item) { Debug.Log(Application.dataPath + item.image_name); imageToLoad = Resources.Load <Sprite>(item.image_name); Debug.Log(imageToLoad); itemImage.GetComponent <Image>().sprite = imageToLoad; }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.layer == LayerMask.NameToLayer("Target")) { GameManager.current.RaiseScore(); RecycleObject.Recycle(transform.parent.gameObject); } }
void CreatePool() { for (int i = 0; i < _defaultPoolSize; ++i) { RecycleObject obj = GameObject.Instantiate(_prefab) as RecycleObject; obj.gameObject.SetActive(false); _pool.Add(obj); } }
void CreatPool() { for (int i = 0; i < DefaultPoolSize; i++) { RecycleObject obj = prefab as RecycleObject; obj.gameObject.SetActive(false); pool.Add(obj); } }
void SpawnMissile() { RecycleObject missile = missileFactory.Get(); missile.Activate(GetMissileSpawnPosition(), buildingManager.GetRandomBuildingPosition()); missile.Destroyed += OnMissileDestroyed; missile.OutOfScreen += OnMissileOutOfScreen; missiles.Add(missile); currentMissileCount++; }
public void itemFound(RecycleObject item) { loadImage(item); itemIndicator.SetActive(true); itemImage.SetActive(true); itemRecyclable.SetActive(true); itemInstructions.SetActive(true); ItemFoundLabel.text = "Item Found"; IsRecyclableLabel.text = "Can it be Recycled: " + item.recyclable; InstructionsLabel.text = "Extra Instructions: " + item.instructions; }
void RestoreMissile(RecycleObject missile) { missile.Destroyed -= OnMissileDestroyed; missile.OutOfScreen -= this.OnMissileOutOfScreen; int index = missiles.IndexOf(missile); missiles.RemoveAt(index); missileFactory.Restore(missile); CheckAllMissileResotred(); }
public RecycleObject Get() { if (pool.Count == 0) { CreatPool(); } int lastIndex = pool.Count - 1; RecycleObject obj = pool[lastIndex]; pool.RemoveAt(lastIndex); obj.gameObject.SetActive(true); return(obj); }
void OnBulletDestroyed(RecycleObject usedBullet) { Vector3 lastBulletPosition = usedBullet.transform.position; usedBullet.Destroyed -= OnBulletDestroyed; bulletFactory.Restore(usedBullet); RecycleObject explosion = explosionFactory.Get(); explosion.Activate(lastBulletPosition); explosion.Destroyed += OnExplosionDestroyed; AudioManager.instance.PlaySound(SoundID.BulletExplosion); }
public void OnFireButtonPressed(Vector3 position) { if (!canShoot) { return; } RecycleObject bullet = bulletFactory.Get(); bullet.Activate(firePosition.position, position); bullet.Destroyed += OnBulletDestroyed; AudioManager.instance.PlaySound(SoundID.Shoot); canShoot = false; }
private static ObjectPool GetObjectPool(RecycleObject reference) { ObjectPool pool = null; if (pools.ContainsKey(reference)) { pool = pools [reference]; } else { var poolContainer = new GameObject(reference.gameObject.name + "ObjectPool"); pool = poolContainer.AddComponent <ObjectPool>(); pool.prefab = reference; pools.Add(reference, pool); } return(pool); }
private static ObjectPool getObjectPool(RecycleObject recycle) { ObjectPool pool = null; if (pools.ContainsKey(recycle)) { pool = pools[recycle]; } else { var obj = new GameObject(recycle.gameObject.name); pool = obj.AddComponent <ObjectPool>(); pool.prefab = recycle; pools.Add(recycle, pool); } return(pool); }
void OnBuildingDestryed(Building building) { AudioManager.instance.PlaySound(SoundID.BuildingExplosion); RecycleObject effect = effectFactory.Get(); effect.Activate(building.transform.position); effect.Destroyed += OnEffectDestroyed; building.Destroyed -= OnBuildingDestryed; int index = buildings.IndexOf(building); buildings.RemoveAt(index); GameObject.Destroy(building.gameObject); if (buildings.Count == 0) { AllBuildingsDestroyed?.Invoke(); } }
public RecycleObject nextObject(Vector2 pos) { RecycleObject obj = null; foreach (var item in poolInstance) { if (!obj.gameObject.activeSelf) { obj = item; obj.transform.position = pos; break; } } if (obj == null) { obj = createItem(pos); } obj.restart(); return(obj); }
public RecycleObject NextObject(Vector3 pos) { RecycleObject instance = null; foreach (var go in poolInstances) { if (go.gameObject.activeSelf != true) { instance = go; instance.transform.position = pos; } } if (instance == null) { instance = CreateInstance(pos); } instance.Restart(); return(instance); }
void OnExplosionDestroyed(RecycleObject usedExplosion) { usedExplosion.Destroyed -= OnExplosionDestroyed; explosionFactory.Restore(usedExplosion); }
public void Restore(RecycleObject obj) { Debug.Assert(obj != null, "NUll object to be returned!"); obj.gameObject.SetActive(false); _pool.Add(obj); }
void OnMissileOutOfScreen(RecycleObject missile) { RestoreMissile(missile); }
void OnMissileDestroyed(RecycleObject missile) { RestoreMissile(missile); missileDestroyed?.Invoke(); }
public void Restore(RecycleObject obj) { obj.gameObject.SetActive(false); pool.Add(obj); }
void OnEffectDestroyed(RecycleObject effect) { effect.Destroyed -= OnEffectDestroyed; effectFactory.Restore(effect); }
public Factory(RecycleObject prefab, int DefaultPoolSize) { this.prefab = prefab; this.DefaultPoolSize = DefaultPoolSize; }