zerochili / cavegeneration Goto Github PK
View Code? Open in Web Editor NEWUnity Study Procedural Cave Generation
Unity Study Procedural Cave Generation
能留个qq或者微信吗,我有些unity学习方面的问题想请教一下
Assets/Scripts/Room.cs 中 UpdateEdgeTiles 函数可能会放入重复的边界点
// 更新房间边缘瓦片集
public void UpdateEdgeTiles(TileType[,] map)
{
edgeTiles.Clear();
// 遍历上下左右四格,判断是否有墙
foreach (Coord tile in tiles)
for (int i = 0; i < 4; i++)
{
int x = tile.tileX + upDownLeftRight[i, 0];
int y = tile.tileY + upDownLeftRight[i, 1];
if (map[x, y] == TileType.Wall)
{
edgeTiles.Add(tile);
continue;
}
}
}
测试函数
// 更新房间边缘瓦片集
public void UpdateEdgeTiles(TileType[,] map)
{
edgeTiles.Clear();
// 遍历上下左右四格,判断是否有墙
foreach (Coord tile in tiles)
for (int i = 0; i < 4; i++)
{
int x = tile.tileX + upDownLeftRight[i, 0];
int y = tile.tileY + upDownLeftRight[i, 1];
if (map[x, y] == TileType.Wall)
{
foreach (var edgeTile in edgeTiles)
{
if (edgeTile.tileX == tile.tileX && edgeTile.tileY == tile.tileY)
{
Debug.Log("重复放入边界点");
break;
}
}
edgeTiles.Add(tile);
continue;
}
}
}
测试结果
可以考虑将 Coord 结构体改成 Vector2Int 然后使用 Contain 判断是否已经放过
// 更新房间边缘瓦片集
public void UpdateEdgeTiles(TileType[,] map)
{
edgeTiles.Clear();
// 遍历上下左右四格,判断是否有墙
foreach (Vector2Int tile in tiles)
for (int i = 0; i < 4; i++)
{
int x = tile.x + upDownLeftRight[i, 0];
int y = tile.y + upDownLeftRight[i, 1];
if (map[x, y] == TileType.Wall && !edgeTiles.Contains(tile))
{
edgeTiles.Add(tile);
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.