void IntegrityCheck(DebrisController controller) { int count = Physics2D.OverlapCircleNonAlloc(transform.position, circleCollider.radius + 0.1f, results); integrity++; for (int i = 0; i < count; i++) { var debrit = results[i].GetComponent <DebrisController>(); if (debrit == null) { continue; } debrit.CheckIntegryty(integrity); } // Iterate over each debrits foreach (var debrit in debrits) { if (debrit.integrity != integrity) { debrit.OnWillBeDestroyed(); Destroy(debrit.gameObject); } } needsIntegrityCheck = false; UpdatePlayerSize(); }
void ReturnRubbleToPool(params object[] vars) { DebrisController rubble = (DebrisController)vars[0]; rubble.SetActive(false); _activeRubble.Remove(rubble); _rubblePools[rubble.id].Push(rubble); }
public void FreeDebris(DebrisController o) { // Prevent double free if (!o.gameObject.activeSelf) { return; } FreeGameObject(o.gameObject); debrisPool.Enqueue(o); }
public void AgglomerateDebrit(DebrisController debrit) { debrits.Add(debrit); debrit.Agglomerate(integrity); debrit.onDestroyed += OnDebritDestroyed; debrit.onLaserReceived += (a) => { needsIntegrityCheck = true; controller = a; }; debrit.transform.SetParent(transform, true); resizeCamera(); UpdatePlayerSize(); }
public DebrisController NewDebris(Vector3 pos) { base.GetGameObject(); DebrisController Debris = debrisPool.Dequeue(); Debris.transform.position = pos; Benchmark.instance.maxSimultaneousDebriss = allocatedObjectCount; return(Debris); }
public Debris(TiledTileLayer collisionLayer, Vector2 position, List <Subtexture> subtextures, float xDir = 0f, float yDir = 0f) : base() { //get initial vel float xSpeed = Nez.Random.range(-maxSpeedX, maxSpeedX); float ySpeed = Nez.Random.range(-maxYSpeed, minYSpeed); if (xDir > 0f) { xSpeed = Nez.Random.range(0f, 2f * maxSpeedX); } else if (xDir < 0f) { xSpeed = Nez.Random.range(-maxSpeedX, 0f); } if (yDir > 0f) { ySpeed = Nez.Random.range(0f, maxYSpeed); } else if (yDir < 0f) { ySpeed = Nez.Random.range(-maxYSpeed, 0f); } //sprite int spriteNum = Nez.Random.range(144, 149); var sprite = new Sprite(subtextures[spriteNum]); sprite.renderLayer = (int)Constants.RenderLayers.Decorative; //sprite.color = new Color(90, 83, 83); addComponent(sprite); //move collide box var box = new BoxCollider(4, 4); box.name = Constants.Strings.MoveCollider; addComponent(box); //tiled mover var tiledMover = new TiledMapMover(collisionLayer); addComponent(tiledMover); //debris controller var controller = new DebrisController(); controller.SetInitialy(new Vector2(xSpeed, ySpeed)); addComponent(controller); this.position = position; }
void Awake() { _transform = transform; //debris _debrisPools = new Stack <DebrisController> [debrisTypes.Length]; _activeDebris = new List <DebrisController>(); for (int j = 0; j < debrisTypes.Length; j++) { _debrisPools[j] = new Stack <DebrisController>(); for (int i = 0; i < POOL_SIZE; i++) { DebrisController controller = (Instantiate(debrisTypes[j]) as Transform).GetComponent <DebrisController>(); controller.SetActive(false); controller.id = j; controller.CachedTransform.parent = _transform; _debrisPools[j].Push(controller); } } //rubble _rubblePools = new Stack <DebrisController> [rubbleTypes.Length]; _activeRubble = new List <DebrisController>(); for (int j = 0; j < rubbleTypes.Length; j++) { _rubblePools[j] = new Stack <DebrisController>(); for (int i = 0; i < POOL_SIZE; i++) { RubbleController controller = (Instantiate(rubbleTypes[j]) as Transform).GetComponent <RubbleController>(); controller.SetActive(false); controller.id = j; controller.CachedTransform.parent = _transform; controller.ReturnToPoolEvent.AddListener += ReturnRubbleToPool; controller.OnPlayerCollisionEvent.AddListener += OnPlayerCollisionEvent; _rubblePools[j].Push(controller); } } StartRandomRubbleGenerator(); }
private void SpawnDebris() { currentSpawnPoint = spawnPoints[Random.Range(1, spawnPoints.Length)]; // spawnPoints[0] = this float randomSpin = Random.Range(0, 180f); float randomScale = Random.Range(scaleRange.x, scaleRange.y); int randomDebris = Random.Range(0, debrisPrefabs.Count); float randomMoveSpeed = Random.Range(randomSpeedMin, randomSpeedMax); StatModifier speedMod = new StatModifier(gameObject, StatType.Engine, StatModType.Flat, baseSpeed + randomMoveSpeed); DebrisController newDebris = Instantiate(debrisPrefabs[randomDebris], currentSpawnPoint.position, currentSpawnPoint.rotation) as DebrisController; newDebris.transform.parent = currentSpawnPoint.transform; newDebris.transform.localScale = new Vector3(randomScale, randomScale, 0); newDebris.GetComponent <Rigidbody2D>().MoveRotation(randomSpin); newDebris.GetComponent <AsteroidStats>().GetStat(StatType.Engine).AddModifier(speedMod); newDebris.GetComponent <AsteroidStats>().SetCurrentHealth(baseHealth * randomScale / 3); }
void AddRubble() { int rubbleId = Random.Range(0, _rubblePools.Length); if (_rubblePools[rubbleId].Count > 0) { float width = rubbleSpawnArea.size.x * 0.5f; float height = rubbleSpawnArea.size.y * 0.5f; _rubbleRayOrigin.x = rubbleSpawnArea.center.x + Random.Range(-width, width); _rubbleRayOrigin.y = rubbleSpawnArea.center.y + Random.Range(-height, height); RaycastHit hit; if (Physics.Raycast(_rubbleRayOrigin, Vector3.forward, out hit, _rubbleRayLenght, (int)ePhysicsLayers.TERRAIN)) { DebrisController currRubble = _rubblePools[rubbleId].Pop(); currRubble.CachedTransform.position = hit.point; currRubble.CachedTransform.parent = activeDebrisParent; currRubble.SetActive(true, Random.Range(rubbleTTL.x, rubbleTTL.y)); _activeDebris.Add(currRubble); } } Invoke("AddRubble", Random.Range(rubbleSpawnRate.x, rubbleSpawnRate.y)); }
public void AddDebrisOnTerrain(Vector3 position, float width, float height, float yAux, int amount) { ResetActiveDebris(); Vector3 center = position; float width_2 = 0.5f * width; float height_2 = 0.5f * height; float yOrigin = center.y + 0.5f * yAux; Vector3 currPos = new Vector3(0f, 0f, 0f); RaycastHit hit; for (int i = 0; i < amount; i++) { int debrisId = Random.Range(0, debrisTypes.Length); currPos.x = Random.Range(-width_2, width_2); currPos.y = yOrigin; currPos.z = Random.Range(-height_2, 0); if (Physics.Raycast(currPos, -Vector3.up, out hit, _rayLenght, (int)ePhysicsLayers.TERRAIN) && !Physics.Raycast(currPos, -Vector3.up, out hit, _rayLenght, (int)ePhysicsLayers.FORBIDDEN_SPAWN_AREA) && !Physics.Raycast(currPos, -Vector3.up, out hit, _rayLenght, (int)ePhysicsLayers.DEBRIS) ) { currPos.y = hit.point.y; DebrisController currDebris = _debrisPools[debrisId].Pop(); currDebris.CachedTransform.position = currPos; currDebris.CachedTransform.parent = activeDebrisParent; currDebris.CachedTransform.rotation = Quaternion.AngleAxis(Random.Range(0f, 360f), Vector3.forward); currDebris.SetActive(true); _activeDebris.Add(currDebris); } else { i -= 1; } } }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>(); debrisController = GameObject.FindGameObjectWithTag("DebrisController").GetComponent <DebrisController>(); }
void Detach() { if (!Debris) m_tDebris = gameObject.AddComponent<DebrisController>(); if (Container.Childs.Count == 1) return; for (int i = 0; i < neighbours.Count; i++) neighbours [i].Neighbours.Remove(this); ResetNeighbours(); Container.DetachBox(this); }
public void Deactivate() { WaitForUpdate(); ResetNeighbours(); if (Temperature >= Container.MaxHeat/* * 0.25f*/) { for (int i=0; i<Container.FlameSpread; ++i) { var tDrop = FirePool.GetFire(); if (tDrop != null) { tDrop.transform.position = transform.position + new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f), 0); tDrop.MaxLife = Random.Range(0.5f, 2.5f); tDrop.transform.SetParent(FirePool.Instance.transform); tDrop.Init(); Rigidbody2D tRB = tDrop.RigidBody; tRB.AddRelativeForce(new Vector2(Random.Range(-1 * tRB.mass, 1 * tRB.mass), Random.Range(-1 * tRB.mass, 1 * tRB.mass)), ForceMode2D.Impulse); } } } Sprite.color = Color.white; Temperature = 0; m_tDebris = null; Container.RemoveChild(this); BoxPool.PoolBox(gameObject); }
void OnDebritDestroyed(DebrisController controller) { resizeCamera(); debrits.Remove(controller); }