private void InitConditionData() { int conditionsCount = generationConditions.Count; for (int i = 0; i < conditionsCount; i++) { GenerationCondition condition = generationConditions[i]; //condition.Init(); condition.SetOwner(this); } }
void PositionOnFloor() { Voxel[] floorVoxels = blueprint.FloorVoxels; List<int> floorVoxelsIndexList = GetFloorVoxelsIndexsList(floorVoxels); roomItemPrefab.Init(); Vector3[] itemWorldPositions = null; Voxel acceptedFloorVoxel = null; ConditionData conditionData; conditionData.endPointDirection = DirectionType.FORWARD; conditionData.blueprint = blueprint; conditionData.roomItemPrefab = roomItemPrefab; conditionData.takenVoxels = acceptedItemVoxels; int infiniteLoopCheckCount = 0, infiniteLoopCheck = 100000;//targetElementsCount << elementsFactory.loopCheckCount; do { if (infiniteLoopCheckCount++ > infiniteLoopCheck) { throw new System.Exception("RoomGenerator::Room generation takes too long. - Possible infinite loop."); } if (floorVoxelsIndexList.Count == 0) break; int randomFloorVoxelIndex = Random.Range(0, floorVoxelsIndexList.Count); randomFloorVoxelIndex = floorVoxelsIndexList[randomFloorVoxelIndex]; floorVoxelsIndexList.Remove(randomFloorVoxelIndex); Voxel randomFloorVoxel = floorVoxels[randomFloorVoxelIndex]; Vector3 randomFloorVoxelPos = randomFloorVoxel.worldPosition; itemWorldPositions = roomItemPrefab.GetOffsetedVoxelPostions(randomFloorVoxelPos); ///// conditionData.randomFloorVoxelPos = randomFloorVoxelPos; conditionData.endPointDirection = DirectionType.FORWARD; bool testPassed = false; int infiniteLoopCheckCount2 = 0, infiniteLoopCheck2 = 100000;//targetElementsCount << elementsFactory.loopCheckCount; int endPointIndex = 0, endPointsCount = roomItemPrefab.endPoint.directions.Count; do { if (infiniteLoopCheckCount2++ > infiniteLoopCheck2) { throw new System.Exception("RoomGenerator::Room item rotation takes too long. - Possible infinite loop."); } conditionData.endPointDirection = roomItemPrefab.endPoint.directions[endPointIndex]; List<GenerationCondition> generationConditions = roomItemPrefab.generationConditions; int conditionsCount = generationConditions.Count; for (int i = 0; i < conditionsCount; i++) { GenerationCondition condition = generationConditions[i]; testPassed = condition.Test(conditionData); if (!testPassed) break; } if (!testPassed) endPointIndex++;//conditionData.rotationIndex++; } while (!testPassed && endPointIndex < endPointsCount); ///// if (!testPassed) continue; acceptedFloorVoxel = randomFloorVoxel; } while (acceptedFloorVoxel == null && floorVoxelsIndexList.Count > 0); if (acceptedFloorVoxel == null) { Debug.Log("No more space in room"); return; } RoomElement item = Instantiate(roomItemPrefab, gameObject.transform); item.transform.position = acceptedFloorVoxel.worldPosition; item.transform.rotation = Quaternion.AngleAxis((float)conditionData.endPointDirection, Vector3.up); InitilizeNewItem(item); }