public IEnumerator CreatePolygon(List <FieldConnectPoint> points, float width, float uvY1, float uvY2) { var candidates = new WeightedValue[] { new WeightedValue { value = width, weight = 1 } }; yield return(CoroutineUtility.CoroutineCycle(CreatePolygon(points, candidates, uvY1, uvY2))); }
public IEnumerator CreatePolygon(List <FieldConnectPoint> points, WeightedValue[] widthCandidates, float uvY1, float uvY2, float disconnectionProb = 0, float decalSize = 1) { if (meshFilter != null) { lastInterruptionTime = System.DateTime.Now; this.widthCandidates = widthCandidates; Prepare(points); yield return(CoroutineUtility.CoroutineCycle(CreateMeshParameter(points, uvY1, uvY2, decalSize))); meshFilter.sharedMesh = CreateMesh(); } }
//第3引数使用していません public IEnumerator CreateBuildingMesh(List <SurroundedArea> areas, BuildingCondition condition, float buildingInterval = 100f) { lastInterruptionTime = System.DateTime.Now; var allBuildingParameters = new List <BuildingParameter>(); var types = new BuildingParameter.BuildingType[] { BuildingParameter.BuildingType.kBuildingA01, BuildingParameter.BuildingType.kBuildingA02, BuildingParameter.BuildingType.kBuildingA03, BuildingParameter.BuildingType.kBuildingA04, BuildingParameter.BuildingType.kBuildingB01, BuildingParameter.BuildingType.kBuildingB02, BuildingParameter.BuildingType.kBuildingB03, BuildingParameter.BuildingType.kBuildingB04, BuildingParameter.BuildingType.kBuildingC01, BuildingParameter.BuildingType.kBuildingC02, BuildingParameter.BuildingType.kBuildingC03, BuildingParameter.BuildingType.kBuildingC04, BuildingParameter.BuildingType.kBuildingD01, BuildingParameter.BuildingType.kBuildingD02, BuildingParameter.BuildingType.kBuildingD03, BuildingParameter.BuildingType.kBuildingD04, BuildingParameter.BuildingType.kBuildingE01, BuildingParameter.BuildingType.kBuildingE02, BuildingParameter.BuildingType.kBuildingE03, BuildingParameter.BuildingType.kBuildingE04, BuildingParameter.BuildingType.kBuildingF01, BuildingParameter.BuildingType.kBuildingF02, BuildingParameter.BuildingType.kBuildingF03, BuildingParameter.BuildingType.kBuildingF04, BuildingParameter.BuildingType.kBuildingG01, BuildingParameter.BuildingType.kBuildingG02, BuildingParameter.BuildingType.kBuildingG03, BuildingParameter.BuildingType.kBuildingG04, BuildingParameter.BuildingType.kBuildingH01, BuildingParameter.BuildingType.kBuildingH02, BuildingParameter.BuildingType.kBuildingH03, BuildingParameter.BuildingType.kBuildingH04, }; var buildableAreas = new List <SurroundedArea>(); yield return(CoroutineUtility.CoroutineCycle(DetectBuildableAreas(areas, condition, buildableAreas))); int max = Mathf.RoundToInt((float)buildableAreas.Count * Mathf.Clamp01(condition.generationRate)); var randomAreas = new List <SurroundedArea>(); for (int i0 = 0; i0 < max; ++i0) { int randomIndex = random.Next(buildableAreas.Count); randomAreas.Add(buildableAreas[randomIndex]); int lastIndex = buildableAreas.Count - 1; buildableAreas[randomIndex] = buildableAreas[lastIndex]; buildableAreas.RemoveAt(lastIndex); } randomAreas.Sort((a, b) => a.GetCenter().x.CompareTo(b.GetCenter().x)); randomAreas.Sort((a, b) => a.GetCenter().z.CompareTo(b.GetCenter().z)); int sqrtBuildingCount = 3; float buildingRatio = 0.25f; float spacingRatio = (1.0f - buildingRatio * sqrtBuildingCount) / (float)(sqrtBuildingCount - 1); for (int i0 = 0; i0 < randomAreas.Count; ++i0) { IReadOnlyList <Vector3> areaPoints = randomAreas[i0].AreaPoints; float minHeight, maxHeight; DetectRange(condition.heightRanges, out minHeight, out maxHeight); int buildingCountInArea = 0; // var demolishCounts = new int[] { 0, 3, 5 }; // int demolishCount = demolishCounts[ random.Next(demolishCounts.Length)]; int demolishCount = 0; var buildingNumbers = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var demolishIndices = new HashSet <int>(); for (int i1 = 0; i1 < demolishCount; ++i1) { int buildingRandomIndex = random.Next(buildingNumbers.Count); demolishIndices.Add(buildingNumbers[buildingRandomIndex]); buildingNumbers.RemoveAt(buildingRandomIndex); } for (int row = 0; row < sqrtBuildingCount; ++row) { Vector3 top1 = Vector3.Lerp(areaPoints[0], areaPoints[3], (buildingRatio + spacingRatio) * row); Vector3 top2 = Vector3.Lerp(areaPoints[1], areaPoints[2], (buildingRatio + spacingRatio) * row); Vector3 bottom1 = Vector3.Lerp(areaPoints[0], areaPoints[3], (buildingRatio + spacingRatio) * row + buildingRatio); Vector3 bottom2 = Vector3.Lerp(areaPoints[1], areaPoints[2], (buildingRatio + spacingRatio) * row + buildingRatio); for (int column = 0; column < sqrtBuildingCount; ++column) { ++buildingCountInArea; if (demolishIndices.Contains(buildingCountInArea) == false) { Vector3 leftTop = Vector3.Lerp(top1, top2, (buildingRatio + spacingRatio) * column); Vector3 rightTop = Vector3.Lerp(top1, top2, (buildingRatio + spacingRatio) * column + buildingRatio); Vector3 rightBottom = Vector3.Lerp(bottom1, bottom2, (buildingRatio + spacingRatio) * column + buildingRatio); Vector3 leftBottom = Vector3.Lerp(bottom1, bottom2, (buildingRatio + spacingRatio) * column); var buildingPoints = new List <Vector3>() { leftTop, rightTop, rightBottom, leftBottom }; var param = new BuildingParameter(buildingPoints); param.SetBuildingType(types[random.Next(types.Length)], random.Next(4)); param.SetBuildingHeight(Mathf.Lerp(minHeight, maxHeight, (float)random.NextDouble())); allBuildingParameters.Add(param); } } } if (System.DateTime.Now.Subtract(lastInterruptionTime).TotalMilliseconds >= LinePolygonCreator.kElapsedTimeToInterrupt) { yield return(null); lastInterruptionTime = System.DateTime.Now; } } int totalBuildingCount = allBuildingParameters.Count; int buildingCountPerMesh = totalBuildingCount / meshCreators.Count; int surplus = totalBuildingCount % meshCreators.Count; for (int i0 = 0; i0 < meshCreators.Count; ++i0) { int startIndex = buildingCountPerMesh * i0; int buildingCount = buildingCountPerMesh + (i0 == meshCreators.Count - 1 ? surplus : 0); List <BuildingParameter> parameters = allBuildingParameters.GetRange(startIndex, buildingCount); if (condition.enabledSort != false) { parameters.Sort((a, b) => (int)a.TextureType - (int)b.TextureType); } meshCreators[i0].BuildingPolygonCreate(parameters, buildingInterval); } }
public IEnumerator CreatePolygon(List <FieldConnectPoint> points, float width) { yield return(CoroutineUtility.CoroutineCycle(CreatePolygon(points, width, 0, 1))); }
public IEnumerator CreatePolygon(List <FieldConnectPoint> points, WeightedValue[] widthCandidates) { yield return(CoroutineUtility.CoroutineCycle(CreatePolygon(points, widthCandidates, 0, 1, 0))); }
public IEnumerator CreatePolygon(List <FieldConnectPoint> points, LinePolygonParameter parameter) { yield return(CoroutineUtility.CoroutineCycle(CreatePolygon(points, parameter.widthCandidates, parameter.uvY1, parameter.uvY2, 0, parameter.decalSize))); }