public void BiomeGenerate() { GetHighestPositon(); int highestPositon = elevationList.IndexOf(maxPosition); grid.cells[highestPositon].visible = true; sttg.SetTileToCell(sttg.collection.spriteCollection[1], grid.CellGetPosition(highestPositon), grid.cells[highestPositon]); for (int i = 0; i < elevationList.Count; i++) { if (elevationList[i] < waterLevel) { //海拔低于海平面且单元格信息为null // water grid.cells[i].visible = false; sttg.SetTileToCell(sttg.collection.spriteCollection[4], grid.CellGetPosition(i), grid.cells[i]); } else if (elevationList[i] > waterLevel && grid.cells[i].info == null) { //海拔高于海平面且单元格信息为null if (GenerateRandom.floatRandom(0.6f, Random.Range(0, 1f))) { grid.cells[i].visible = true; sttg.SetTileToCell(sttg.collection.spriteCollection[6], grid.CellGetPosition(i), grid.cells[i]); } else { grid.cells[i].visible = true; sttg.SetTileToCell(sttg.collection.spriteCollection[0], grid.CellGetPosition(i), grid.cells[i]); } } else if (elevationList[i] > waterLevel && grid.cells[i].info != null) { Debug.Log("Is City"); //海报高于海平面且单元格信息不为null } else if (elevationList[i] == waterLevel) { grid.cells[i].visible = true; sttg.SetTileToCell(sttg.collection.spriteCollection[0], grid.CellGetPosition(i), grid.cells[i]); } } }
//Once LMB pressed, check texture if it is null and assign it to cell public void SetTileToCell(/*Texture2D tex*/ GameObject obj) { if (obj != null) { lastCell = grid.cellHighlighted; v3 = grid.CellGetPosition(grid.CellGetIndex(lastCell)); //grid.CellSetSprite(grid.CellGetIndex(lastCell),Color.white,collection.spriteCollection[0]); // GameObject instance = Instantiate(obj); properities = instance.GetComponent <CellProperities>(); properities.SetTileToDataCollection(lastCell); //properities.SetToCellInfo(lastCell); properitiesList.AddNewDataToList(properities); instance.transform.localPosition = v3; obj = null; //grid.CellSetTexture(grid.CellGetIndex(lastCell),tex2D); //tex2D = null; } else { Debug.Log("Need to assign texture to variable first!"); } }