/// <summary> /// target content will be added or update it's possition if already added /// </summary> public static void Process(IChunkContent processedContent) { Bounds2DInt processedContentBounds = PathFinder.ToChunkPosition(processedContent.chunkContentBounds); ChunkContentMetaData metaData; if (content.TryGetValue(processedContent, out metaData)) { Bounds2DInt currentContentBounds = metaData.lastUpdate; if (currentContentBounds == processedContentBounds) { return; //nothing to change since it occupy same space } GetChunkRemoveContent(currentContentBounds, processedContent); IncludeBounds(processedContentBounds); GetChunkAddContent(processedContentBounds, processedContent); content[processedContent] = new ChunkContentMetaData(processedContentBounds); } else { if (init == false) { beforeInit.Add(processedContent); return; } IncludeBounds(processedContentBounds); GetChunkAddContent(processedContentBounds, processedContent); content[processedContent] = new ChunkContentMetaData(processedContentBounds); } }
private static void GetChunkRemoveContent(Bounds2DInt bounds, IChunkContent content) { for (int x = bounds.minX; x < bounds.maxX + 1; x++) { for (int z = bounds.minY; z < bounds.maxY + 1; z++) { GetChunkContent(x, z).Remove(content); } } }
public static void RemoveContent(IChunkContent removedContent) { if (init) { ChunkContentMetaData metaData; if (content.TryGetValue(removedContent, out metaData)) { //Bounds2DInt bounds = metaData.lastUpdate; GetChunkRemoveContent(metaData.lastUpdate, removedContent); content.Remove(removedContent); } //else it's already probably removed or there is assebly reload } else { beforeInit.Remove(removedContent); } }
public static void RemoveContent <T>(List <T> processedContentArray) where T : IChunkContent { if (init) { for (int i = 0; i < processedContentArray.Count; i++) { IChunkContent removedContent = processedContentArray[i]; ChunkContentMetaData metaData; if (content.TryGetValue(removedContent, out metaData)) { //Bounds2DInt bounds = metaData.lastUpdate; GetChunkRemoveContent(metaData.lastUpdate, removedContent); content.Remove(removedContent); } } } else { for (int i = 0; i < processedContentArray.Count; i++) { beforeInit.Remove(processedContentArray[i]); } } }
/// <summary> /// target content will be added or update it's possition if already added /// </summary> public static void Process <T>(List <T> processedContentList) where T : IChunkContent { //Debug.Log(processedContentList.Count); if (processedContentList == null || processedContentList.Count == 0) { return; } Bounds2DInt first = PathFinder.ToChunkPosition(processedContentList[0].chunkContentBounds); int minX = first.minX, minZ = first.minY, maxX = first.maxX, maxZ = first.maxY; Bounds2DInt[] array = new Bounds2DInt[processedContentList.Count]; array[0] = first; for (int i = 1; i < processedContentList.Count; i++) { Bounds2DInt curRange = PathFinder.ToChunkPosition(processedContentList[i].chunkContentBounds); array[i] = curRange; if (minX > curRange.minX) { minX = curRange.minX; } if (minZ > curRange.minY) { minZ = curRange.minY; } if (maxX < curRange.maxX) { maxX = curRange.maxX; } if (maxZ < curRange.maxY) { maxZ = curRange.maxY; } } IncludeBounds(new Bounds2DInt(minX, minZ, maxX, maxZ)); for (int i = 0; i < processedContentList.Count; i++) { Bounds2DInt processedContentBounds = array[i]; IChunkContent processedContent = processedContentList[i]; ChunkContentMetaData metaData; if (content.TryGetValue(processedContent, out metaData)) { Bounds2DInt currentContentBounds = metaData.lastUpdate; if (currentContentBounds == processedContentBounds) { return; //nothing to change since it occupy same space } GetChunkRemoveContent(currentContentBounds, processedContent); GetChunkAddContent(processedContentBounds, processedContent); content[processedContent] = new ChunkContentMetaData(processedContentBounds); } else { if (init == false) { beforeInit.Add(processedContent); return; } GetChunkAddContent(processedContentBounds, processedContent); content[processedContent] = new ChunkContentMetaData(processedContentBounds); } } //SceneDebug(); }