本文整理汇总了C#中Vector4.XY方法的典型用法代码示例。如果您正苦于以下问题:C# Vector4.XY方法的具体用法?C# Vector4.XY怎么用?C# Vector4.XY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector4
的用法示例。
在下文中一共展示了Vector4.XY方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CarveRoom
public static bool CarveRoom(Dungeon dungeon, Corridor corridor, Vector4 brushSizeVariation, Vector2 maxRoomSize, int maxBrushStrokes, out Room room)
{
Vector2 startingPosition = corridor ? corridor.Bounds.max : Vector2.zero;
Vector2 corridorDirection = corridor ? corridor.Direction : Vector2.zero;
Vector2 minBrushSize = brushSizeVariation.XY();
Vector2 maxBrushSize = brushSizeVariation.ZW();
Rect brush = new Rect(startingPosition, Vector2.zero);
//move the room one up or to the left so it aligns properly to the corridor
brush.x -= corridorDirection.y;
brush.y -= corridorDirection.x;
room = Room.CreateInstance(brush.position, Dungeon.Random);
if (brush.x < 0 || brush.y < 0
|| !AdjustCoordinate(corridorDirection, minBrushSize, dungeon.Size, ref brush))
{
return false;
}
bool enoughSpaceForRoom = !dungeon.OverlapsCorridor(brush.position, minBrushSize);
while (!corridorDirection.IsZero()
&& !enoughSpaceForRoom //if the room is currently intersecting a corridor
&& ((corridorDirection.y != 0 && brush.x >= 0 && brush.x + minBrushSize.x - 1 > room.Bounds.x) //and it can be moved to the left (orUp)
|| (corridorDirection.x != 0 && brush.y >= 0 && brush.y + minBrushSize.y - 1 > room.Bounds.y))) //while still being attached to the corridor
{
//move the room and check again
brush.x -= corridorDirection.y;
brush.y -= corridorDirection.x;
enoughSpaceForRoom = !dungeon.OverlapsCorridor(brush.position, minBrushSize);//!dungeon.SearchInArea(pos, minSize, CellType.corridor);
}
if (!enoughSpaceForRoom) //if a room with the minimum size possible would still intersect a corridor, stop trying to make it
return false;
brush.x = Mathf.Clamp(brush.x, 0, dungeon.Width);
brush.y = Mathf.Clamp(brush.y, 0, dungeon.Height);
bool roomCarved = false;
//mark cells at random locations within the room, until the maximum tries is reached
for (int tries = 0; tries < maxBrushStrokes; tries++)
{
if (CreateBrush(
minBrushSize,
maxBrushSize,
startingPosition,
corridorDirection,
dungeon,
room,
ref brush))
{
if (!brush.size.IsZero())
{
if (!dungeon.OverlapsCorridor(brush.position, brush.size))
{
if (AddCells(brush, dungeon, room) > 0)
roomCarved = true;
}
}
}
MoveBrush(dungeon, startingPosition, corridorDirection, room, minBrushSize, maxBrushSize, ref brush);
}
if (room.Position.x < 0 || room.Position.y < 0)
throw new ArgumentOutOfRangeException("Room was carved outside of dungeon!\n" + room);
return roomCarved;
}