public void Recommand() { if (recommendation != null) { recommendationIndex = null; recommendation.visualize(); recommendationIndex = recommendation.recommendedIndex; //Debug.Log("recommendedIndex=" + recommendationIndex); if (recommendationIndex.HasValue) { recommendedScheme = schemes[recommendationIndex.Value]; } //Debug.Log("recommendedScheme=" + recommendedScheme); } }
public override void Execute() { if (matrix == null) { return; } PlaningScheme scheme = matrix.recommendedScheme; //Debug.Log("scheme="+scheme); if (scheme == null) { return; } //Debug.Log("has scheme"); int total = 0; for (int i = 0; i < scheme.counts.Count; i++) { total += scheme.counts[i]; } total = Mathf.Clamp(total, 0, inputs.shapes.Count); if (buildings == null) { buildings = new List <SGBuilding>(); } else { //先删除多出来的building int dif = buildings.Count - total; for (int i = 0; i < dif; i++) { int index = buildings.Count - 1; buildings[index].ClearAllAssociated(); buildings.RemoveAt(index); }//for } int typeIndex = 0; int nextLevel = scheme.counts[0]; for (int i = 0; i < total; i++) { if (i >= nextLevel) { //Debug.LogFormat("i={0}, typeIndex={1}, total={2}", i, typeIndex,total); typeIndex++; nextLevel = nextLevel + scheme.counts[typeIndex]; } ShapeObject so = inputs.shapes[i]; //补足不够的building if (i >= buildings.Count) { SOPoint sop = SOPoint.CreatePoint(new Vector3(i * 40, 0, 0)); SGBuilding building = SGBuilding.CreateApt(sop, new Vector3(30, 60, 15)); building.Execute(); buildings.Add(building); } BuildingType bt = scheme.buildingTypes[typeIndex]; Vector3 size = new Vector3(bt.width, bt.height, bt.depth); SGBuilding b = buildings[i]; b.gPlaning.inputs.shapes[0].Position = so.Position; b.SetSize(size); b.Execute(); }//for //update particle system if (psys != null) { psys.particles.Clear(); for (int i = 0; i < buildings.Count; i++) { GraphNode g = buildings[i].gPlaning; ShapeObject sop = g.inputs.shapes[0]; psys.particles.Add(sop); } } }
public void genGrid(int maxCountA = 10, int maxCountB = 10, int maxCountC = 10) { if (cells == null) { cells = new List <GameObject>(); } //countAs = new List<float>(); //countBs = new List<float>(); //countCs = new List<float>(); float targetGFA = siteProp.siteArea * siteProp.plotRatio; positions = new List <Vector3>(); List <float> difs = new List <float>(); List <float> gfas = new List <float>(); //calculate all options and update cell positions for (int i = 0; i < maxCountA; i++) { for (int k = 0; k < maxCountB; k++) { float designAreaA = (float)i * buildingTypes[0].GFA; float designAreaB = (float)k * buildingTypes[2].GFA; float remainGFA = targetGFA - designAreaA - designAreaB; int j = Mathf.RoundToInt(remainGFA / buildingTypes[1].GFA); if (j < 0) { j = 0; } float designArea = ((float)i * buildingTypes[0].GFA) + ((float)j * buildingTypes[1].GFA) + ((float)k * buildingTypes[2].GFA) ; gfas.Add(designArea); float dif = targetGFA - designArea; dif = Mathf.Abs(dif); difs.Add(dif); if (j > 0) { Debug.LogFormat("targetGFA={4}, remain={3},i={0},j={1},k={2}", i, j, k, remainGFA, targetGFA); } PlaningScheme scheme = new PlaningScheme(); if (j > 0) { Debug.LogFormat("---Pre i={0},j={1},k={2}", i, j, k); } scheme.AddTypeAndQuantity(buildingTypes[0], i); scheme.AddTypeAndQuantity(buildingTypes[1], j); scheme.AddTypeAndQuantity(buildingTypes[2], k); if (j > 0) { Debug.LogFormat("---Pst i={0},j={1},k={2}", scheme.counts[0], scheme.counts[1], scheme.counts[2]); } scheme.site = siteProp; scheme.gfa = designArea; schemes.Add(scheme); Vector3 pos = new Vector3(i * cellSize, j * cellSize * 0.3f, k * cellSize); positions.Add(pos); //Debug.LogFormat("A:{0}, B:{1}, C:{2}, dif:{3}", i, j, k, dif); } } //Debug.LogFormat("minDif={0}, maxDif={1}", minDif, maxDif); Color[] colorSet = new Color[] { Color.blue, Color.green, Color.yellow, Color.red }; for (int i = 0; i < positions.Count; i++) { if (i >= cells.Count) { GameObject oi = GameObject.CreatePrimitive(PrimitiveType.Cube); oi.AddComponent <OnMouseOverCalCell>(); cells.Add(oi); } GameObject o = cells[i]; o.transform.position = (positions[i]); o.transform.localScale = new Vector3(cellSize, cellSize, cellSize); o.layer = 10; OnMouseOverCalCell cc = o.GetComponent <OnMouseOverCalCell>(); cc.scheme = schemes[i]; }// for i Recommand(); }