public Vector3 GetRandPosInCurMap(ESpawnType type) { if (type == ESpawnType.Character) { Vector3 pos = Vector3.zero; bool findValidPos = false; for (int i = 0; i < ConstValue._MaxLoopTime; i++) { pos = GetRandPosInCurMap(ConstValue._DefaultBodyLength + 1, ConstValue._DefaultBodyLength + 1); var c = Physics2D.OverlapCircleNonAlloc(pos, ConstValue._BodyUnitSize, _CheckColliders, 0xffff ^ LayerMask.GetMask("Food")); if (c == 0) { findValidPos = true; break; } } if (!findValidPos) { Debugger.LogError("cannot find a valid position! "); } return(pos); } else if (type == ESpawnType.Food) { return(GetRandPosInCurMap(1, 1)); } return(GetRandPosInCurMap()); }
public void DisableAllSpawnType(ESpawnType argSpawnType) { for (int i = 0; i < m_spawnTypeNames.Length; i++) { if (m_spawnTypeNames[i].type == argSpawnType) { DisableChildren(objectPoolContainer.transform.Find(m_spawnTypeNames[i].name)); } } }
//The spawner routine increases variety and intensity as time goes on private IEnumerator spawnRoutine() { float _timer = 0.0f; int _levelStage = 0; ESpawnType _spawnType = ESpawnType.Enemy; while (true) { _levelStage = Mathf.FloorToInt(m_multiplierCounter / MultiplierTime); _timer += Time.deltaTime; _spawnType = (ESpawnType)Random.Range(0, Mathf.Clamp(_levelStage, 0, (int)ESpawnType.EnumSize)); if (_timer > SpawnRate) { switch (_spawnType) { case ESpawnType.Pillar: ObstacleObjectManager.SpawnObject(0, _levelStage); break; case ESpawnType.Enemy: EnemyObjectManager.SpawnObject(0, _levelStage); break; case ESpawnType.PillarEnemy: bool _side = Random.Range(0, 2) != 0; EnemyObjectManager.SpawnObject(_side ? -1 : 1, _levelStage); ObstacleObjectManager.SpawnObject(_side ? 1 : -1, _levelStage); break; case ESpawnType.EnemyEnemy: EnemyObjectManager.SpawnObject(1, _levelStage); EnemyObjectManager.SpawnObject(-1, _levelStage); break; case ESpawnType.PillarPillar: int _tempStepsMid = ObstacleObjectManager.StepsFromMiddle; int _tempStepsEdge = ObstacleObjectManager.StepsFromEdge; ObstacleObjectManager.StepsFromEdge = -6; ObstacleObjectManager.StepsFromMiddle = 2; ObstacleObjectManager.SpawnObject(1, _levelStage); ObstacleObjectManager.SpawnObject(-1, _levelStage); ObstacleObjectManager.StepsFromEdge = _tempStepsEdge; ObstacleObjectManager.StepsFromMiddle = _tempStepsMid; break; } _timer = 0.0f; } yield return(null); } }
public void CreatePool(GameObject argGameObject, int argAmount, ESpawnType argSpawnType = ESpawnType.eUndefined) { GameObject typeParent = null; GameObject parent; Queue <GameObject> queue; for (int i = 0; i < m_spawnTypeNames.Length; i++) { if (m_spawnTypeNames[i].type == argSpawnType) { typeParent = objectPoolContainer.transform.Find(m_spawnTypeNames[i].name).gameObject; break; } } if (m_objectPool.ContainsKey(argGameObject.name)) { parent = typeParent.transform.Find("P_" + argGameObject.name).gameObject; queue = m_objectPool[argGameObject.name]; } else { Queue <GameObject> newQueue = new Queue <GameObject>(); m_objectPool.Add(argGameObject.name, newQueue); queue = newQueue; parent = new GameObject("P_" + argGameObject.name); parent.transform.parent = typeParent.transform; } for (int i = 0; i < argAmount; i++) { GameObject newGameObject = Instantiate(argGameObject, parent.transform); newGameObject.name = "PL_" + newGameObject.name; newGameObject.SetActive(false); queue.Enqueue(newGameObject); } }