// NOTE : 지정된 카운트 만큼의 피쳐 타입의 영역을 생성 private void CreateFeatureTypeArea(Tile currentTile, FeatureType featureType, List <ClimateType> climateConditions, List <TerrainType> terrainConditions, ref int remainCreateCount) { if (remainCreateCount <= 0) { return; } var nearTiles = TileHelper.GetNearTilesRandomSorted(currentTile).Where(x => { bool isUnSet = x.FeatureType == FeatureType.None; bool isCorrectClimate = climateConditions.Any(condition => (int)condition == x.ClimateType); bool isCorrectTerrain = terrainConditions.Any(condition => condition == x.TerrainType); return(isUnSet && isCorrectClimate && isCorrectTerrain); }).ToArray(); foreach (var nearTile in nearTiles) { if (remainCreateCount <= 0) { return; } nearTile.SetupFeatureType(featureType); --remainCreateCount; } foreach (var nearTile in nearTiles) { CreateFeatureTypeArea(nearTile, featureType, climateConditions, terrainConditions, ref remainCreateCount); } }
public void Create(IndexPair indexRange) { TileHelper.ClearAllTiles(); TileHelper.maxIndex = new IndexPair(indexRange.X, indexRange.Y); for (int y = 0; y < indexRange.Y; y++) { for (int x = 0; x < indexRange.X; x++) { var tile = Instantiate(tilePrefab, tilesRoot); // NOTE : 실제 위치 설정 var pos = tile.transform.localPosition = new Vector3( (x + y * 0.5f - y / 2) * (HexMetrics.innerRadius * 2f), 0f, y * (HexMetrics.outerRadius * 1.5f)); // NOTE : 좌표계 설정 tile.Setup(new IndexPair(x, y)); TileModel.tiles.Add(tile); // NOTE : 라벨 설정 Text label = Instantiate <Text>(cellLabelPrefab); label.rectTransform.SetParent(gridCanvas.transform, false); label.rectTransform.anchoredPosition = new Vector2(pos.x, pos.z); label.text = tile.Coordinates.ToStringOnSeparateLines(); label.tag = "TileUI"; TileModel.tileLabels.Add(label); } } Debug.Log(TileModel.tiles.Count); // TODO : 타일 환경설정은 새로운 좌표계에 맞춰서 리팩토링 for (int i = 0; i < allContinentTiles.Length; ++i) { allContinentTiles[i] = new List <Tile>(); } foreach (var firstContinentTileIndex in firstContinentTileIndexs) { CreateRandomContinent(firstContinentTileIndex); } SetupTerrainType(); SetupClimateType(); SetupFeatureType(); TileDataJsonConverter.SetTileTerrainData(TileModel.tiles); for (int i = 0; i < allContinentTiles.Length; ++i) { var currentContinentName = TilePropertyInfo.ContinentNames[i]; var currentContinent = allContinentTiles[i]; Debug.Log($"{currentContinentName} : {currentContinent.Count}"); } }
public static void ClearAll() { GameObjectUtility.ClearComponentListAndDelete(tiles); GameObjectUtility.ClearComponentListAndDelete(tileLabels); GameObjectUtility.DeleteGameObjectsFromTags(new string[] { "Tile", "TileUI" }); if (hexMesh == null) { hexMesh = FindObjectOfType <HexMesh>(); } TileHelper.ClearHexMesh(); }
private void CreateContinentTilesFromNearTiles(List <ContinentTile> continentTiles, int influence, int percentBasicUnit) { bool isEnd = false; for (int i = 0; i < continentTiles.Count && !isEnd; ++i) { var currentTile = continentTiles[i]; if (currentTile.isClosed) { continue; } currentTile.isClosed = true; foreach (var nearTile in TileHelper.GetNearTiles(currentTile.tile)) { if (!continentTiles.Select(x => x.tile).Contains(nearTile) && !allContinentTiles.Any(x => x.Contains(nearTile))) { // NOTE : 전체 타일 사이즈 대비 각 타일의 영향력으로 계산된 영향력 퍼센트 int influencePercent = influence / percentBasicUnit; // NOTE : 마지막 타일 생성 타이밍에 대륙타일 숫자가 최소에 미치지 못하면 강제로 대륙타일 생성 bool lastInfluenceTile = influence == 1; bool isForceContinentTile = lastInfluenceTile && numOfLeastContinentTiles > continentTiles.Count; if (!isForceContinentTile) { // NOTE : 랜덤 확률. 랜덤 확률보다 대륙타일 확률이 낮으면 생성하지 않는걸로 함 int randomResult = UnityEngine.Random.Range(0, 100); if (randomResult > influencePercent) { continue; } } var newContinentTile = nearTile; newContinentTile.ContinentInfluence = influence; continentTiles.Add(new ContinentTile(newContinentTile, influencePercent)); if (!isForceContinentTile) { --influence; } if (influence <= 0 || numOfMaxContinentTiles <= continentTiles.Count) { isEnd = true; break; } } } } }
public void TouchCell(int button, Vector3 position, bool isOnce) { position = transform.InverseTransformPoint(position); var clickedTile = TileHelper.GetTile(HexCoordinates.FromPosition(position)); if (clickedTile != null) { if (isOnce) { ClickOnceEvent(button, clickedTile); } else { ClickContinuingEvent(button, clickedTile); } } }
public override void OnInspectorGUI() { if (GUILayout.Button("create tile map")) { tileCreater.ReCreateMap(); } if (GUILayout.Button("delete all tiles")) { TileHelper.ClearAllTiles(); } serializedObject.Update(); foreach (var property in serializeProperty) { EditorGUILayout.PropertyField(property); } serializedObject.ApplyModifiedProperties(); }
public void FindPath() { var startTile = TileHelper.GetTile(findPathStart); var endTile = TileHelper.GetTile(findPathEnd); PathFinderManager.StartPathFinding(true, startTile, endTile, (outPath) => { path = outPath; TileHelper.SetTilesColorToEnvironment(); float strengthPerPath = 1.0f / outPath.Count; int cnt = 0; foreach (var path in path) { path.color = new Color(strengthPerPath * ++cnt, 0, 0, 1); } TileHelper.ReDrawHexMesh(); }); }
// NOTE : 대륙 타일 설정 페이즈 private void CreateContinentTilePhase(IndexPair firstContinentTileIndex, ref List <Tile> continentTileList) { var continentTilesForCreate = new List <ContinentTile>(); // NOTE : 퍼센트를 계산하기 위한 기본 단위. 전체 타일의 1%에 해당 int percentBasicUnit = numOfMaxContinentTiles / 100; // NOTE : 대륙 영향력. 영향력이 높을수록 인접타일이 대륙일 확률이 높음 int influence = (int)(numOfMaxContinentTiles * Mathf.Clamp(influenceOfContinent, 0, 1)); // NOTE : 첫 대륙타일을 기준으로 대륙을 생성. var firstContinentTile = new ContinentTile(TileHelper.GetTile(firstContinentTileIndex), --influence / percentBasicUnit); continentTilesForCreate.Add(firstContinentTile); // NOTE : 최소 생성 수를 넘을때까지 대륙 생성 알고리즘을 반복 do { CreateContinentTilesFromNearTiles(continentTilesForCreate, influence, percentBasicUnit); } while (Mathf.Clamp(numOfLeastContinentTiles, 0, numOfMaxContinentTiles) > continentTilesForCreate.Count); Debug.Log($"{continentTilesForCreate.Count}continentTiles have created"); continentTileList = continentTilesForCreate.Select(x => x.tile).ToList(); }
private void OnDisable() { TileHelper.ClearAllTiles(); }
public void ReCreateMap() { Create(tileRange); TileHelper.InitHexMesh(); }