Here are the examples of the csharp api System.Collections.Generic.Dictionary.ContainsKey(Vector3Int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
51 Examples
19
Source : VoxelSet.cs
with GNU General Public License v3.0
from artembakhanov
with GNU General Public License v3.0
from artembakhanov
private List<int> GetVoxelForEditing(Vector3Int key)
{
if (!Voxels.ContainsKey(key))
{
Voxels.Add(key, new List<int>());
VoxelVersions.Add(key, version);
}
return Voxels[key];
}
19
Source : VoxelSet.cs
with GNU General Public License v3.0
from artembakhanov
with GNU General Public License v3.0
from artembakhanov
private List<int> GetVoxel(Vector3Int key)
{
if (!Voxels.ContainsKey(key))
{
return new List<int>();
}
return Voxels[key];
}
19
Source : VoxelSet1.cs
with GNU General Public License v3.0
from artembakhanov
with GNU General Public License v3.0
from artembakhanov
private List<int> GetVoxelForEditing(Vector3Int key)
{
if (!Voxels.ContainsKey(key))
{
Voxels.Add(key, new List<int>());
}
return Voxels[key];
}
19
Source : VoxelSet1.cs
with GNU General Public License v3.0
from artembakhanov
with GNU General Public License v3.0
from artembakhanov
private List<int> GetVoxel(Vector3Int key)
{
if (!Voxels.ContainsKey(key))
{
return new List<int>();
}
return Voxels[key];
}
19
Source : EdgeDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Edge<E> FromCartesianCoordinate(Vector3 cartesianCoordinate)
{
Vector3Int coord = edgePositionProvider.FromCartesianCoordinate(cartesianCoordinate);
if (!edgesByPosition.ContainsKey(coord)) return null;
return edgesByPosition[coord];
}
19
Source : TileDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Tile<T> FromTileRotated60DegreeClockwise(Tile<T> center, Tile<T> pointToRotate)
{
Vector3Int coord = tilePositionProvider.FromTileRotated60DegreeClockwise(center.Position, pointToRotate.Position);
if (!tilesByPosition.ContainsKey(coord)) return null;
return tilesByPosition[coord];
}
19
Source : CornerPositionProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Vector3Int FromCartesianCoordinate(Vector3 cartesianCoordinate, out bool cornerIsOnMap)
{
if (coordinateWrapper != null) cartesianCoordinate = coordinateWrapper.WrapCartesianCoordinate(cartesianCoordinate);
Vector3Int coord = HexConverter.CartesianCoordToClosestCornerCoord(cartesianCoordinate);
cornerIsOnMap = false;
if (cornerIndexByPosition.ContainsKey(coord)) cornerIsOnMap = true;
return coord;
}
19
Source : HexMap.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
private void CreateEdgeIndex()
{
Vector3IntEqualityComparer vector3IntEqualityComparer = new Vector3IntEqualityComparer();
EdgeIndexByPosition = new Dictionary<Vector3Int, int>(vector3IntEqualityComparer);
int edgeIndex = 0;
foreach (var kvp in TileIndexByPosition)
{
List<Vector3Int> edges = HexGrid.GetEdges.OfTile(kvp.Key);
foreach (Vector3Int edge in edges)
{
Vector3Int edgeToAdd = edge;
if (CoordinateWrapper != null) edgeToAdd = CoordinateWrapper.WrapEdgeCoordinate(edgeToAdd);
if (!EdgeIndexByPosition.ContainsKey(edgeToAdd))
{
EdgeIndexByPosition.Add(edgeToAdd, edgeIndex);
edgeIndex++;
}
}
}
EdgePositions = new Vector3Int[EdgeIndexByPosition.Count];
foreach(var kvp in EdgeIndexByPosition)
{
EdgePositions[kvp.Value] = kvp.Key;
}
}
19
Source : HexMap.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
private void CreateCornerIndex()
{
Vector3IntEqualityComparer vector3IntEqualityComparer = new Vector3IntEqualityComparer();
CornerIndexByPosition = new Dictionary<Vector3Int, int>(vector3IntEqualityComparer);
CornerPositions = new Vector3Int[CornerIndexByPosition.Count];
int cornerIndex = 0;
foreach (var kvp in TileIndexByPosition)
{
List<Vector3Int> corners = HexGrid.GetCorners.OfTile(kvp.Key);
foreach (Vector3Int corner in corners)
{
Vector3Int cornerToAdd = corner;
if (CoordinateWrapper != null) cornerToAdd = CoordinateWrapper.WrapCornerCoordinate(cornerToAdd);
if (!CornerIndexByPosition.ContainsKey(cornerToAdd))
{
CornerIndexByPosition.Add(cornerToAdd, cornerIndex);
cornerIndex++;
}
}
}
CornerPositions = new Vector3Int[CornerIndexByPosition.Count];
foreach (var kvp in CornerIndexByPosition)
{
CornerPositions[kvp.Value] = kvp.Key;
}
}
19
Source : HexUtility.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public static List<Vector3Int> RemoveInvalidCoordinates(List<Vector3Int> inputCollection, Dictionary<Vector3Int, int> validCollection)
{
for (int i = 0; i < inputCollection.Count; i++)
{
Vector3Int element = inputCollection.ElementAt(i);
if (!validCollection.ContainsKey(element))
{
inputCollection.Remove(element);
i--;
}
}
return inputCollection;
}
19
Source : EdgeDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Edge<E> BetweenNeighbouringCorners(Vector3Int cornerA, Vector3Int cornerB)
{
Vector3Int coord = edgePositionProvider.BetweenNeighbouringCorners(cornerA,cornerB);
if (!edgesByPosition.ContainsKey(coord)) return null;
return edgesByPosition[coord];
}
19
Source : TileDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Tile<T> FromCartesianCoordinate(Vector3 cartesianCoordinate)
{
Vector3Int coord = tilePositionProvider.FromCartesianCoordinate(cartesianCoordinate);
if (!tilesByPosition.ContainsKey(coord)) return null;
return tilesByPosition[coord];
}
19
Source : TileDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Tile<T> FromTileRotated60DegreeCounterClockwise(Vector3Int center, Vector3Int pointToRotate)
{
Vector3Int coord = tilePositionProvider.FromTileRotated60DegreeCounterClockwise(center, pointToRotate);
if (!tilesByPosition.ContainsKey(coord)) return null;
return tilesByPosition[coord];
}
19
Source : EdgePositionProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Vector3Int FromCartesianCoordinate(Vector3 cartesianCoordinate, out bool edgeIsOnMap)
{
if (coordinateWrapper != null) cartesianCoordinate = coordinateWrapper.WrapCartesianCoordinate(cartesianCoordinate);
Vector3Int coord = HexConverter.CartesianCoordToClosestEdgeCoord(cartesianCoordinate);
edgeIsOnMap = false;
if (edgeIndexByPosition.ContainsKey(coord)) edgeIsOnMap = true;
return coord;
}
19
Source : CornerDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Corner<C> FromCartesianCoordinate(Vector3 cartesianCoordinate)
{
Vector3Int coord = cornerPositionProvider.FromCartesianCoordinate(cartesianCoordinate);
if (!cornersByPosition.ContainsKey(coord)) return null;
return cornersByPosition[coord];
}
19
Source : EdgeDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Edge<E> BetweenNeighbouringTiles(Vector3Int tileA, Vector3Int tileB)
{
Vector3Int coord = edgePositionProvider.BetweenNeighbouringTiles(tileA, tileB);
if (!edgesByPosition.ContainsKey(coord)) return null;
return edgesByPosition[coord];
}
19
Source : TileDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Tile<T> FromTileRotated60DegreeClockwise(Vector3Int center, Vector3Int pointToRotate)
{
Vector3Int coord = tilePositionProvider.FromTileRotated60DegreeClockwise(center, pointToRotate);
if (!tilesByPosition.ContainsKey(coord)) return null;
return tilesByPosition[coord];
}
19
Source : TileDataProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Tile<T> FromTileRotated60DegreeCounterClockwise(Tile<T> center, Tile<T> pointToRotate)
{
Vector3Int coord = tilePositionProvider.FromTileRotated60DegreeCounterClockwise(center.Position, pointToRotate.Position);
if (!tilesByPosition.ContainsKey(coord)) return null;
return tilesByPosition[coord];
}
19
Source : TilePositionProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Vector3Int FromCartesianCoordinate(Vector3 cartesianCoordinate, out bool tileIsOnMap)
{
if (coordinateWrapper != null) cartesianCoordinate = coordinateWrapper.WrapCartesianCoordinate(cartesianCoordinate);
Vector3Int coord = HexConverter.CartesianCoordToTileCoord(cartesianCoordinate);
tileIsOnMap = false;
if (tileIndexByPosition.ContainsKey(coord)) tileIsOnMap = true;
return coord;
}
19
Source : TilePositionProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Vector3Int FromTileRotated60DegreeClockwise(Vector3Int center, Vector3Int pointToRotate, out bool tileIsOnMap)
{
Vector3Int rotated = HexGrid.GetTile.FromTileRotated60DegreeClockwise(center, pointToRotate);
if (coordinateWrapper != null) rotated = coordinateWrapper.WrapTileCoordinate(rotated);
tileIsOnMap = false;
if (tileIndexByPosition.ContainsKey(rotated)) tileIsOnMap = true;
return rotated;
}
19
Source : TilePositionProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public Vector3Int FromTileRotated60DegreeCounterClockwise(Vector3Int center, Vector3Int pointToRotate, out bool tileIsOnMap)
{
Vector3Int rotated = HexGrid.GetTile.FromTileRotated60DegreeCounterClockwise(center, pointToRotate);
if (coordinateWrapper != null) rotated = coordinateWrapper.WrapTileCoordinate(rotated);
tileIsOnMap = false;
if (tileIndexByPosition.ContainsKey(rotated)) tileIsOnMap = true;
return rotated;
}
19
Source : TilePositionProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public bool IsInputCoordinateOnMap(Vector3Int inputTileCoordinate)
{
if (coordinateWrapper != null) inputTileCoordinate = coordinateWrapper.WrapTileCoordinate(inputTileCoordinate);
if (tileIndexByPosition.ContainsKey(inputTileCoordinate)) return true;
else return false;
}
19
Source : TilePositionProvider.cs
with MIT License
from AurelWu
with MIT License
from AurelWu
public bool IsInputCoordinateOnMap(Vector3 inputCartesianCoordinate)
{
if (coordinateWrapper != null) inputCartesianCoordinate = coordinateWrapper.WrapCartesianCoordinate(inputCartesianCoordinate);
Vector3Int tileCoordinate = HexConverter.CartesianCoordToTileCoord(inputCartesianCoordinate);
if (tileIndexByPosition.ContainsKey(tileCoordinate)) return true;
else return false;
}
19
Source : TerrainGenerator.cs
with MIT License
from bbtarzan12
with MIT License
from bbtarzan12
void GenerateChunkByTargetPosition()
{
if (target == null)
return;
Vector3Int targetPosition = VoxelUtil.WorldToChunk(target.position, chunkSize);
if (lastTargetChunkPosition == targetPosition)
return;
foreach (ChunkNode chunkNode in generateChunkQueue)
{
Vector3Int deltaPosition = targetPosition - chunkNode.chunkPosition;
if (chunkSpawnSize.x < Mathf.Abs(deltaPosition.x) || chunkSpawnSize.y < Mathf.Abs(deltaPosition.y) || chunkSpawnSize.y < Mathf.Abs(deltaPosition.z))
{
generateChunkQueue.Remove(chunkNode);
continue;
}
generateChunkQueue.UpdatePriority(chunkNode, (targetPosition - chunkNode.chunkPosition).sqrMagnitude);
}
for (int x = targetPosition.x - chunkSpawnSize.x; x <= targetPosition.x + chunkSpawnSize.x; x++)
{
for (int z = targetPosition.z - chunkSpawnSize.y; z <= targetPosition.z + chunkSpawnSize.y; z++)
{
Vector3Int chunkPosition = new Vector3Int(x, 0, z);
if (chunks.ContainsKey(chunkPosition))
continue;
ChunkNode newNode = new ChunkNode {chunkPosition = chunkPosition};
if (generateChunkQueue.Contains(newNode))
continue;
generateChunkQueue.Enqueue(newNode, (targetPosition - chunkPosition).sqrMagnitude);
}
}
lastTargetChunkPosition = targetPosition;
}
19
Source : TerrainGenerator.cs
with MIT License
from bbtarzan12
with MIT License
from bbtarzan12
Chunk GenerateChunk(Vector3Int chunkPosition)
{
if (chunks.ContainsKey(chunkPosition))
return chunks[chunkPosition];
GameObject chunkGameObject = new GameObject(chunkPosition.ToString());
chunkGameObject.transform.SetParent(transform);
chunkGameObject.transform.position = VoxelUtil.ChunkToWorld(chunkPosition, chunkSize);
Chunk newChunk = chunkGameObject.AddComponent<Chunk>();
newChunk.Init(chunkPosition, this);
newChunk.CanUpdate += delegate
{
for (int x = chunkPosition.x - 1; x <= chunkPosition.x + 1; x++)
{
for (int z = chunkPosition.z - 1; z <= chunkPosition.z + 1; z++)
{
Vector3Int neighborChunkPosition = new Vector3Int(x, chunkPosition.y, z);
if (chunks.TryGetValue(neighborChunkPosition, out Chunk neighborChunk))
{
if (!neighborChunk.Initialized)
{
return false;
}
}
else
{
return false;
}
}
}
return true;
};
chunks.Add(chunkPosition, newChunk);
return newChunk;
}
19
Source : Tilemap3D.cs
with MIT License
from ChevyRay
with MIT License
from ChevyRay
public void UpdateUVs()
{
var filter = GetComponent<MeshFilter>();
if (texture == null || filter.sharedMesh == null)
return;
rendUVs.Clear();
float w = texture.width;
float h = texture.height;
foreach (var tile in tiles)
{
var p = tile.pos;
if (tile.top != null && !tileLookup.ContainsKey(p + new Vector3Int(0, 1, 0)))
UpdateUVs(tile, tile.top, w, h, tile.rotTop);
if (tile.bottom != null && !tileLookup.ContainsKey(p + new Vector3Int(0, -1, 0)))
UpdateUVs(tile, tile.bottom, w, h, tile.rotBottom);
if (tile.front != null && !tileLookup.ContainsKey(p + new Vector3Int(0, 0, 1)))
UpdateUVs(tile, tile.front, w, h, tile.rotFront);
if (tile.back != null && !tileLookup.ContainsKey(p + new Vector3Int(0, 0, -1)))
UpdateUVs(tile, tile.back, w, h, tile.rotBack);
if (tile.right != null && !tileLookup.ContainsKey(p + new Vector3Int(1, 0, 0)))
UpdateUVs(tile, tile.right, w, h, tile.rotRight);
if (tile.left != null && !tileLookup.ContainsKey(p + new Vector3Int(-1, 0, 0)))
UpdateUVs(tile, tile.left, w, h, tile.rotLeft);
}
filter.sharedMesh.SetUVs(0, rendUVs);
filter.sharedMesh.UploadMeshData(Application.isPlaying);
filter.mesh = filter.sharedMesh;
}
19
Source : VoxelController.cs
with Apache License 2.0
from decentraland
with Apache License 2.0
from decentraland
VoxelPrefab CreateVoxel(Vector3Int position)
{
if (!createdVoxels.ContainsKey(position))
{
VoxelPrefab go = GameObject.Instantiate(voxelPrefab.gameObject, position, lastVoxelCreated.rootEnreplacedy.gameObject.transform.rotation).GetComponent<VoxelPrefab>();
createdVoxels.Add(position, go);
return go;
}
return null;
}
19
Source : ChunkGrid.cs
with MIT License
from EmmetOT
with MIT License
from EmmetOT
public bool IsOccupied(Vector3Int coordinate) => m_grid.ContainsKey(coordinate);
19
Source : SectionMeshManager.cs
with MIT License
from Jin-Yuhan
with MIT License
from Jin-Yuhan
public void MarkSectionMeshDirty(Vector3Int section, bool forceLoadMesh, bool important)
{
if (!forceLoadMesh && !m_SectionMeshMap.ContainsKey(section))
{
return;
}
if (m_DirtySections.Add(section))
{
if (important)
{
m_ImportantDirtySectionQueue.Enqueue(section);
}
else
{
m_NotImportantDirtySectionQueue.Enqueue(section);
}
}
}
19
Source : Chunk.cs
with MIT License
from marian42
with MIT License
from marian42
public void AddBlock(Slot slot) {
if (this.renderersByPosition.ContainsKey(slot.Position)) {
foreach (var renderer in this.renderersByPosition[slot.Position]) {
this.Renderers.Remove(renderer);
}
}
var renderers = slot.GameObject.GetComponentsInChildren<Renderer>();
this.renderersByPosition[slot.Position] = renderers;
this.Renderers.AddRange(renderers);
this.ExteriorBlocksVisible = true;
this.GameObjects.Add(slot.GameObject);
slot.GameObject.SetActive(this.InRenderRange);
}
19
Source : Chunk.cs
with MIT License
from marian42
with MIT License
from marian42
public void RemoveBlock(Slot slot) {
if (!this.renderersByPosition.ContainsKey(slot.Position)) {
return;
}
foreach (var renderer in this.renderersByPosition[slot.Position]) {
this.Renderers.Remove(renderer);
}
this.GameObjects.Remove(slot.GameObject);
}
19
Source : CullingData.cs
with MIT License
from marian42
with MIT License
from marian42
private Chunk getChunk(Vector3Int chunkAddress) {
if (this.Chunks.ContainsKey(chunkAddress)) {
return this.Chunks[chunkAddress];
}
var chunk = new Chunk(new Bounds(this.GetChunkCenter(chunkAddress), Vector3.one * AbstractMap.BLOCK_SIZE * this.ChunkSize));
this.Chunks[chunkAddress] = chunk;
this.ChunksInRange.Add(chunk);
return chunk;
}
19
Source : CullingData.cs
with MIT License
from marian42
with MIT License
from marian42
public Room GetRoom(Vector3Int position) {
if (this.RoomsByPosition.ContainsKey(position)) {
return this.RoomsByPosition[position];
} else {
return null;
}
}
19
Source : CullingData.cs
with MIT License
from marian42
with MIT License
from marian42
public void AddSlot(Slot slot) {
if (!slot.Collapsed) {
return;
}
var chunk = this.getChunkFromPosition(slot.Position);
if (!slot.Module.Prototype.IsInterior) {
for (int i = 0; i < 6; i++) {
var face = slot.Module.GetFace(i);
if (face.IsOcclusionPortal) {
var portal = this.getPortal(slot.Position, i);
if (portal.Room != null && !portal.Room.Portals.Contains(portal)) {
portal.Room.Portals.Add(portal);
}
}
}
chunk.AddBlock(slot);
return;
}
Room room = null;
for (int i = 0; i < 6; i++) {
var face = slot.Module.GetFace(i);
if (face.Connector == 1 || face.IsOcclusionPortal) {
continue;
}
var neighbor = slot.GetNeighbor(i);
if (neighbor == null) {
continue;
}
if (neighbor.Collapsed && this.RoomsByPosition.ContainsKey(neighbor.Position) && !neighbor.Module.GetFace((i + 3) % 6).IsOcclusionPortal) {
if (room == null) {
room = this.RoomsByPosition[neighbor.Position];
} if (room != this.RoomsByPosition[neighbor.Position]) {
room = this.mergeRooms(this.RoomsByPosition[neighbor.Position], room);
}
}
}
if (room == null) {
room = new Room();
chunk.Rooms.Add(room);
}
room.Slots.Add(slot);
foreach (var renderer in slot.GameObject.GetComponentsInChildren<Renderer>()) {
room.Renderers.Add(renderer);
}
this.RoomsByPosition[slot.Position] = room;
for (int i = 0; i < 6; i++) {
var face = slot.Module.GetFace(i);
if (face.Connector == 1) {
continue;
}
var neighbor = slot.GetNeighbor(i);
if (face.IsOcclusionPortal || (neighbor != null && neighbor.Collapsed && (!neighbor.Module.Prototype.IsInterior || neighbor.Module.GetFace((i + 3) % 6).IsOcclusionPortal))) {
var portal = this.getPortal(slot.Position, i);
room.Portals.Add(portal);
var otherRoom = portal.Follow(room);
if (otherRoom != null && !otherRoom.Portals.Contains(portal)) {
otherRoom.Portals.Add(portal);
}
}
}
this.updatePortals(slot.Position, room);
}
19
Source : CullingData.cs
with MIT License
from marian42
with MIT License
from marian42
private void removePortal(Portal portal) {
if (this.portalsByPosition.ContainsKey(portal.Position1)) {
this.portalsByPosition[portal.Position1][portal.Direction] = null;
if (this.portalsByPosition[portal.Position1].All(p => p == null)) {
this.portalsByPosition.Remove(portal.Position1);
}
}
this.getChunkFromPosition(portal.Position1).Portals.Remove(portal);
this.getChunkFromPosition(portal.Position2).Portals.Remove(portal);
if (portal.Room1 != null) {
portal.Room1.Portals.Remove(portal);
}
if (portal.Room2 != null) {
portal.Room2.Portals.Remove(portal);
}
}
19
Source : CullingData.cs
with MIT License
from marian42
with MIT License
from marian42
public void RemoveSlot(Slot slot) {
var chunk = this.getChunkFromPosition(slot.Position);
chunk.RemoveBlock(slot);
if (this.RoomsByPosition.ContainsKey(slot.Position)) {
var room = this.RoomsByPosition[slot.Position];
foreach (var portal in room.Portals.ToArray()) {
this.removePortal(portal);
}
foreach (var roomSlot in room.Slots) {
this.outdatedSlots.Add(roomSlot.Position);
this.RoomsByPosition.Remove(roomSlot.Position);
}
this.removeRoom(room);
}
this.outdatedSlots.Remove(slot.Position);
}
19
Source : CullingData.cs
with MIT License
from marian42
with MIT License
from marian42
private Portal getPortal(Vector3Int position, int direction) {
if (direction >= 3) {
position = position + Orientations.Direction[direction];
direction -= 3;
}
if (this.portalsByPosition.ContainsKey(position)) {
var array = this.portalsByPosition[position];
if (array[direction] == null) {
var portal = new Portal(position, direction, this);
array[direction] = portal;
this.addPortalToChunks(portal);
return portal;
} else {
return array[direction];
}
} else {
var portal = new Portal(position, direction, this);
var array = new Portal[3];
array[direction] = portal;
this.portalsByPosition[position] = array;
this.addPortalToChunks(portal);
return portal;
}
}
19
Source : InfiniteMap.cs
with MIT License
from marian42
with MIT License
from marian42
public override Slot GetSlot(Vector3Int position) {
if (position.y >= this.Height || position.y < 0) {
return null;
}
if (this.slots.ContainsKey(position)) {
return this.slots[position];
}
if (this.IsOutsideOfRangeLimit(position)) {
return null;
}
this.slots[position] = new Slot(position, this, this.defaultColumn.GetSlot(position));
return this.slots[position];
}
19
Source : InfiniteMap.cs
with MIT License
from marian42
with MIT License
from marian42
public bool IsSlotInitialized(Vector3Int position) {
return this.slots.ContainsKey(position);
}
19
Source : PositionBuffer.cs
with MIT License
from mytoboggan
with MIT License
from mytoboggan
public static void Update(){
GameObjects = new Dictionary<Vector3Int, List<GameObject>>();
var levelTransform = GameObject.Find("Levels").transform.GetChild(0);
foreach (Transform item in levelTransform)
{
foreach (var tileItem in item.GetComponentsInChildren<BoxCollider>())
{
var tilePos = Utils.Vec3ToInt(tileItem.transform.position);
if(!GameObjects.ContainsKey(tilePos)){
var list = new List<GameObject>();
GameObjects.Add(tilePos,list);
}
GameObjects[tilePos].Add(item.gameObject);
}
}
}
19
Source : PositionBuffer.cs
with MIT License
from mytoboggan
with MIT License
from mytoboggan
internal static List<GameObject> Get(Vector3Int pos)
{
if(gameObjects == null){
Update();
}
if(GameObjects.ContainsKey(pos)) return GameObjects[pos];
return null;
}
19
Source : MeshGenerator.cs
with MIT License
from SebLague
with MIT License
from SebLague
void InitVisibleChunks () {
if (chunks==null) {
return;
}
CreateChunkHolder ();
Vector3 p = viewer.position;
Vector3 ps = p / boundsSize;
Vector3Int viewerCoord = new Vector3Int (Mathf.RoundToInt (ps.x), Mathf.RoundToInt (ps.y), Mathf.RoundToInt (ps.z));
int maxChunksInView = Mathf.CeilToInt (viewDistance / boundsSize);
float sqrViewDistance = viewDistance * viewDistance;
// Go through all existing chunks and flag for recyling if outside of max view dst
for (int i = chunks.Count - 1; i >= 0; i--) {
Chunk chunk = chunks[i];
Vector3 centre = CentreFromCoord (chunk.coord);
Vector3 viewerOffset = p - centre;
Vector3 o = new Vector3 (Mathf.Abs (viewerOffset.x), Mathf.Abs (viewerOffset.y), Mathf.Abs (viewerOffset.z)) - Vector3.one * boundsSize / 2;
float sqrDst = new Vector3 (Mathf.Max (o.x, 0), Mathf.Max (o.y, 0), Mathf.Max (o.z, 0)).sqrMagnitude;
if (sqrDst > sqrViewDistance) {
existingChunks.Remove (chunk.coord);
recycleableChunks.Enqueue (chunk);
chunks.RemoveAt (i);
}
}
for (int x = -maxChunksInView; x <= maxChunksInView; x++) {
for (int y = -maxChunksInView; y <= maxChunksInView; y++) {
for (int z = -maxChunksInView; z <= maxChunksInView; z++) {
Vector3Int coord = new Vector3Int (x, y, z) + viewerCoord;
if (existingChunks.ContainsKey (coord)) {
continue;
}
Vector3 centre = CentreFromCoord (coord);
Vector3 viewerOffset = p - centre;
Vector3 o = new Vector3 (Mathf.Abs (viewerOffset.x), Mathf.Abs (viewerOffset.y), Mathf.Abs (viewerOffset.z)) - Vector3.one * boundsSize / 2;
float sqrDst = new Vector3 (Mathf.Max (o.x, 0), Mathf.Max (o.y, 0), Mathf.Max (o.z, 0)).sqrMagnitude;
// Chunk is within view distance and should be created (if it doesn't already exist)
if (sqrDst <= sqrViewDistance) {
Bounds bounds = new Bounds (CentreFromCoord (coord), Vector3.one * boundsSize);
if (IsVisibleFrom (bounds, Camera.main)) {
if (recycleableChunks.Count > 0) {
Chunk chunk = recycleableChunks.Dequeue ();
chunk.coord = coord;
existingChunks.Add (coord, chunk);
chunks.Add (chunk);
UpdateChunkMesh (chunk);
} else {
Chunk chunk = CreateChunk (coord);
chunk.coord = coord;
chunk.SetUp (mat, generateColliders);
existingChunks.Add (coord, chunk);
chunks.Add (chunk);
UpdateChunkMesh (chunk);
}
}
}
}
}
}
}
19
Source : Pathfinder.cs
with MIT License
from SebLague
with MIT License
from SebLague
Grid CreateSubGrid (Vector3 localUp) {
float maxRadius = 1000;
Vector3 axisA = new Vector3 (localUp.y, localUp.z, localUp.x);
Vector3 axisB = Vector3.Cross (localUp, axisA);
Node[, ] nodes = new Node[gridResolution, gridResolution];
float border = 0f;
for (int y = 0; y < gridResolution; y++) {
for (int x = 0; x < gridResolution; x++) {
Vector2 percent = new Vector2 (x, y) / (gridResolution - 1);
percent = new Vector2 (Mathf.Lerp (border, 1 - border, percent.x), Mathf.Lerp (border, 1 - border, percent.y));
Vector3 pointOnUnitCube = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;
// Distribute on sphere
float x2 = pointOnUnitCube.x * pointOnUnitCube.x;
float y2 = pointOnUnitCube.y * pointOnUnitCube.y;
float z2 = pointOnUnitCube.z * pointOnUnitCube.z;
float sx = pointOnUnitCube.x * Mathf.Sqrt (1f - y2 / 2f - z2 / 2f + y2 * z2 / 3f);
float sy = pointOnUnitCube.y * Mathf.Sqrt (1f - x2 / 2f - z2 / 2f + x2 * z2 / 3f);
float sz = pointOnUnitCube.z * Mathf.Sqrt (1f - x2 / 2f - y2 / 2f + x2 * y2 / 3f);
Vector3 pointOnUnitSphere = new Vector3 (sx, sy, sz);
// Raycast for collisions:
Ray ray = new Ray (pointOnUnitSphere * maxRadius, -pointOnUnitSphere);
RaycastHit hit;
if (Physics.SphereCast (ray, nodeRadius, out hit)) {
bool walkable = obstacleMask != (obstacleMask | (1 << hit.collider.gameObject.layer));
Node node = new Node ();
node.position = hit.point;
node.walkable = walkable;
nodes[x, y] = node;
} else {
Debug.LogError ("No collision");
}
}
}
// Add neighbours
for (int y = 0; y < gridResolution; y++) {
for (int x = 0; x < gridResolution; x++) {
for (int offsetY = -1; offsetY <= 1; offsetY++) {
for (int offsetX = -1; offsetX <= 1; offsetX++) {
if (offsetX != 0 || offsetY != 0) {
int nX = x + offsetX;
int nY = y + offsetY;
if (nX >= 0 && nX < gridResolution && nY >= 0 && nY < gridResolution) {
if (nodes[nX, nY].walkable) {
nodes[x, y].AddNeighbour (nodes[nX, nY]);
}
}
}
}
}
// Handle edge nodes which need to link to neighbouring grids
// TODO: Use better method, this is gross and slow
if (x == 0 || x == gridResolution - 1 || y == 0 || y == gridResolution - 1) {
Vector2 percent = new Vector2 (x, y) / (gridResolution - 1);
Vector3 p = localUp + (percent.x - .5f) * 2 * axisA + (percent.y - .5f) * 2 * axisB;
p *= gridResolution;
Vector3Int coordOnUnitCube = new Vector3Int ((int) p.x, (int) p.y, (int) p.z);
if (nodes[x, y].walkable) {
if (edgeDictionary.ContainsKey (coordOnUnitCube)) {
var neighbour = edgeDictionary[coordOnUnitCube];
if (neighbour.walkable) {
neighbour.AddNeighbour (nodes[x, y]);
nodes[x, y].AddNeighbour (neighbour);
}
} else {
edgeDictionary.Add (coordOnUnitCube, nodes[x, y]);
}
}
}
}
}
return new Grid () { nodes = nodes };
}
19
Source : AStar.cs
with MIT License
from sturdyspoon
with MIT License
from sturdyspoon
public static List<Vector3Int> FindPath(IGraph graph, Vector3Int start, Vector3Int goal, Func<Vector3Int, Vector3Int, float> heuristic)
{
PriorityQueue<Vector3Int> open = new PriorityQueue<Vector3Int>();
open.Enqueue(start, 0);
Dictionary<Vector3Int, Vector3Int> cameFrom = new Dictionary<Vector3Int, Vector3Int>();
cameFrom[start] = start;
Dictionary<Vector3Int, float> costSoFar = new Dictionary<Vector3Int, float>();
costSoFar[start] = 0;
while (open.Count > 0)
{
Vector3Int current = open.Dequeue();
if (current == goal)
{
break;
}
foreach (Vector3Int next in graph.Neighbors(current))
{
float newCost = costSoFar[current] + graph.Cost(current, next);
if (!costSoFar.ContainsKey(next) || newCost < costSoFar[next])
{
costSoFar[next] = newCost;
float priority = newCost + heuristic(next, goal);
open.Enqueue(next, priority);
cameFrom[next] = current;
}
}
}
List<Vector3Int> path = null;
if (cameFrom.ContainsKey(goal))
{
path = new List<Vector3Int>();
Vector3Int v = goal;
while (v != start)
{
RemoveDuplicates(path, v);
path.Add(v);
v = cameFrom[v];
}
RemoveDuplicates(path, start);
path.Add(start);
path.Reverse();
}
return path;
}
19
Source : NBTChunk.cs
with MIT License
from wetstreet
with MIT License
from wetstreet
void InitTileEnreplacedy()
{
if (hasInitTileEnreplacedy)
return;
foreach (Vector3Int pos in tileEnreplacedyList)
{
if (!tileEnreplacedyObjs.ContainsKey(pos))
{
int sectionIndex = pos.y / 16;
TagNodeCompound Section = Sections[sectionIndex] as TagNodeCompound;
TagNodeByteArray Blocks = Section["Blocks"] as TagNodeByteArray;
TagNodeByteArray Data = Section["Data"] as TagNodeByteArray;
int yInSection = pos.y % 16;
int blockPos = yInSection * 16 * 16 + pos.z * 16 + pos.x;
byte rawType = Blocks.Data[blockPos];
NBTBlock generator = NBTGeneratorManager.GetMeshGenerator(rawType);
byte blockData = NBTHelper.GetNibble(Data.Data, blockPos);
GameObject obj = generator.GetTileEnreplacedyGameObject(this, blockData, pos);
tileEnreplacedyObjs[pos] = obj;
}
}
hasInitTileEnreplacedy = true;
}
19
Source : NBTChunk.cs
with MIT License
from wetstreet
with MIT License
from wetstreet
public void RemoveTileEnreplacedy(Vector3Int pos)
{
pos.x -= x * 16;
pos.z -= z * 16;
if (tileEnreplacedyObjs.ContainsKey(pos))
{
GameObject obj = tileEnreplacedyObjs[pos];
tileEnreplacedyObjs.Remove(pos);
tileEnreplacedyList.Remove(pos);
Object.Destroy(obj);
}
}
19
Source : TorchMeshGenerator.cs
with MIT License
from wetstreet
with MIT License
from wetstreet
public void RemoveTorchAt(Vector3Int globalPos)
{
if (pos2objDict.ContainsKey(globalPos))
{
GameObject obj = pos2objDict[globalPos];
pos2objDict.Remove(globalPos);
Object.Destroy(obj);
}
}
19
Source : ChunkManager.cs
with MIT License
from wetstreet
with MIT License
from wetstreet
public static void RemoveBlockOrientation(Vector3Int pos)
{
if (orientationDict.ContainsKey(pos))
{
orientationDict.Remove(pos);
}
}
19
Source : ChunkManager.cs
with MIT License
from wetstreet
with MIT License
from wetstreet
public static CSBlockOrientation GetBlockOrientation(Vector3Int pos)
{
if (orientationDict.ContainsKey(pos))
{
return orientationDict[pos];
}
else
{
return CSBlockOrientation.Default;
}
}
19
Source : LocalServer.cs
with MIT License
from wetstreet
with MIT License
from wetstreet
static void DeleteBlock(Vector3Int pos, List<CSVector3Int> returnList)
{
//删除数据
SetBlockByte(pos, CSBlockType.None);
if (dependenceDict.ContainsKey(pos))
{
dependenceDict.Remove(pos);
}
if (orientationDict.ContainsKey(pos))
{
orientationDict.Remove(pos);
}
//告知客户端
returnList.Add(pos.ToCSVector3Int());
//删除上方的植物
if (ChunkMeshGenerator.type2texcoords[GetBlockByte(pos + Vector3Int.up)].isPlant)
{
DeleteBlock(pos + Vector3Int.up, returnList);
}
//递归删除依赖于这个方块的数据
List<Vector3Int> bedependents = GetBedependentList(pos);
foreach (Vector3Int bedependPos in bedependents)
{
DeleteBlock(bedependPos, returnList);
}
}
See More Examples