private void ForestFireSearchBuild(Vector3 input) { _searchCount++; _physicsObjects.Clear(); // 2. Initialize Empty Q List <FFS_struct> q = new List <FFS_struct>(); FFS_struct Parent = new FFS_struct { Block = World.GetBlock(input) }; Parent.Block.SearchMarker = _searchCount; Parent.Block.Position = Vector3Int.RoundToInt(input); if (Parent.Block.Data.IsSolid) { Parent.Object = Instantiate(PhysicsPrefab, Parent.Block.Position, Quaternion.identity); Parent.Object.GetComponent <Rigidbody>().Sleep(); _physicsObjects.Add(Parent.Object); } q.AddRange(CheckDirections(Parent)); while (q.Count > 0) { Parent = q[0]; q.RemoveAt(0); if (((Parent.Block.Position - input).magnitude >= Depth) && (_physicsObjects.Count > 100)) { Parent.Object.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } else { q.AddRange(CheckDirections(Parent)); } if (_physicsObjects.Count > 2000) { break; } } }
private List <FFS_struct> CheckDirections(FFS_struct parent) { List <FFS_struct> output = new List <FFS_struct>(); foreach (var dir in BlockProperties.DirectionVector) { FFS_struct neighbor = new FFS_struct(); Vector3Int pos = parent.Block.Position + dir; neighbor.Block = World.GetBlock(pos); neighbor.Block.Position = pos; if (neighbor.Block.Data.IsSolid) { if (neighbor.Block.SearchMarker != _searchCount) { neighbor.Block.SearchMarker = _searchCount; neighbor.Object = Instantiate(PhysicsPrefab, neighbor.Block.Position, Quaternion.identity); neighbor.Object.GetComponent <Rigidbody>().Sleep(); _physicsObjects.Add(neighbor.Object); output.Add(neighbor); if (parent.Block.Data.IsSolid) { var fj = neighbor.Object.AddComponent <FixedJoint>(); if (neighbor.Block.Strength < parent.Block.Strength) { fj.breakForce = neighbor.Block.Strength; fj.breakTorque = neighbor.Block.Strength; } else { fj.breakForce = parent.Block.Strength; fj.breakTorque = parent.Block.Strength; } fj.connectedBody = parent.Object.GetComponent <Rigidbody>(); } } } } return(output); }