using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Random = UnityEngine.Random;
public class SimpleRandomWalkDungeonGenerator : MonoBehaviour
{
[SerializeField]
protected Vector2Int startPosition = Vector2Int.zero;
[SerializeField]
private int iterations = 10;
[SerializeField]
public int walkLenght = 10;
[SerializeField]
public bool startRandomlyEachIteraction = true;
public void RunProceduralGeneration()
{
HashSet<Vector2Int> floorPositions = RunRandomWalk();
foreach (var position in floorPositions)
{
Debug.Log(position);
}
}
protected HashSet<Vector2Int> RunRandomWalk()
{
var currentPosition = startPosition;
HashSet<Vector2Int> floorPositions = new HashSet<Vector2Int>();
for (int i = 0; i < iterations; i++)
{
var path = ProceduralGenerationAlgorithms.SimpleRandomWalk(currentPosition, walkLenght);
floorPositions.UnionWith(path);
if (startRandomlyEachIteraction)
currentPosition = floorPositions.ElementAt(Random.Range(0, floorPositions.Count));
}
return floorPositions;
}
}
on click
출력 확인
'Project T > 진행' 카테고리의 다른 글
[팀 프로젝트] - 랜덤 워크와 이진 공간 분할 알고리즘(맵 생성4) (0) | 2021.12.01 |
---|---|
[팀 프로젝트] - 랜덤 워크와 이진 공간 분할 알고리즘(맵 생성3) (0) | 2021.11.30 |
[팀 프로젝트] - 랜덤 워크와 이진 공간 분할 알고리즘(맵 생성) (0) | 2021.11.26 |
[팀 프로젝트] - 랜덤 워크와 이진 공간 분할 알고리즘 맵(셋팅) (0) | 2021.11.26 |
[팀 프로젝트] Enemy Animation (0) | 2021.11.24 |