//xi yi -> plant group list's center. public void AddPlantToGroup(MapTileInfo[,] mapTiles, int xi, int yi, PlantGroupInfo info, PlantGroupTableInfo tableInfo) { int range = tableInfo.GroupRange; PlantTableInfo plantInfo = null; Plant plant = null; for (int x_i = xi - range; x_i < xi + range; x_i++) { if (x_i < 0) { continue; } if (x_i >= MapTileInfo.ColumnCount) { break; } for (int y_i = yi - range; y_i < yi + range; y_i++) { if (y_i < 0) { continue; } if (y_i >= MapTileInfo.RowCount) { break; } if (JUtil.NextFloat() > tableInfo.Chance) { continue; } int index = JUtil.NextInt(0, tableInfo.Plants.Count); int plantId = tableInfo.Plants [index]; MapTileInfo curTile = mapTiles [x_i, y_i]; if (curTile.GetBuildableObject <BuildableObject>() == null && TableManager.Instance.PlantList.TryGetValue(plantId, out plantInfo)) { if (!TableManager.Instance.IsAdaptableEnvironment(plantInfo.ProperTemperature, plantInfo.ProperHumidity, curTile.Temperature, curTile.Humidity)) { continue; } GameObject obj = ResourcesManager.Instance.GetObject("Plant"); plant = obj.GetComponent <Plant> (); plant.SetPlantInfo(plantInfo, x_i, y_i); plant.transform.position = MapTile.IndexToPosition(x_i, y_i); mapTiles [x_i, y_i].SetBuildableObject(plant); info.AddPlant(plant); } } } }
public void SetPlantInfo(PlantTableInfo info, int xi, int yi) { _plantInfo = info; _xi = xi; _yi = yi; }