/// <summary> /// Clean up all current obstacles /// </summary> public void Setdown() { foreach (KeyValuePair <ObstacleData, ObstaclePool> keyValue in pool) { keyValue.Value.ResetWeight(); keyValue.Value.pool.ForEach(item => { item.Setdown(); }); } nextObst = null; weightQueue.Clear(); }
/// <summary> /// Get an object from the pool /// If nothing is available, instantiate a new one /// </summary> /// <param name="obData"></param> /// <returns></returns> public ObstacleTilemap GetPool(ObstacleData obData) { List <ObstacleTilemap> obsPool = pool[obData].pool; ObstacleTilemap obstacle; for (int i = 0; i < obsPool.Count; i++) { obstacle = obsPool[i]; if (obstacle.isActiveAndEnabled == false) { return(obstacle); } } obstacle = Instantiate(obData.GetObstacle()); obstacle.transform.parent = obstaclePool.transform; obsPool.Add(obstacle); return(obstacle); }
/// <summary> /// Spawn the next obstacle /// </summary> /// <param name="pos"></param> /// <returns></returns> public ObstacleTilemap SpawnNext() { ObstacleTilemap obstacle = Spawn(this.nextObst); //Modify the weight so it does not occor too many times in a row. pool[this.nextObst].ApplyWeightMod(); if (weightQueue.Count >= currentLevel.data.obstacles.Count) { pool[weightQueue[qIndex]].ResetWeight(); weightQueue.RemoveAt(qIndex); qIndex++; if (qIndex >= currentLevel.data.obstacles.Count) { qIndex = 0; } } CalculateTotalWeight(); weightQueue.Add(this.nextObst); this.nextObst = Roll(); return(obstacle); }
/// <summary> /// Spawn a specific obstacle /// </summary> /// <param name="data"></param> /// <param name="pos"></param> /// <returns></returns> public ObstacleTilemap Spawn(ObstacleData obData) { ObstacleTilemap obstacle = GetPool(obData); return(obstacle); }
public void SetupResetObst() { this.nextObst = currentLevel.data.resetObstacle; }