private ChunkController[,] GetControllersAsGrid(IEnumerable <ChunkController> chunkControllers) { ChunkController[,] grid = new ChunkController[Chunk.KEEP_LOADED, Chunk.KEEP_LOADED]; List <ChunkController> ccs = new List <ChunkController>(chunkControllers); ccs.Sort((cc1, cc2) => { if (cc1.Chunk.Position.x < cc2.Chunk.Position.x) { return(-1); } else if (cc1.Chunk.Position.x > cc2.Chunk.Position.x) { return(1); } if (cc1.Chunk.Position.y < cc2.Chunk.Position.y) { return(-1); } return(1); }); for (int x = 0; x < Chunk.KEEP_LOADED; x++) { for (int y = 0; y < Chunk.KEEP_LOADED; y++) { grid[x, y] = ccs[x * Chunk.KEEP_LOADED + y]; } } return(grid); }
public override void OnInspectorGUI() { _buttonStyle = new GUIStyle(GUI.skin.button) { fontSize = 14, fixedHeight = 50 }; WorldController worldController = target as WorldController; var chunkControllers = GetControllersOrdered(worldController.ChunkControllers); GUILayout.BeginVertical("Box"); _selectedIndex = GUILayout.SelectionGrid(_selectedIndex, ChunkController.ChunkPositionStrings(chunkControllers).ToArray(), Chunk.KEEP_LOADED, _buttonStyle); GUILayout.EndVertical(); if (_selectedIndex != -1) { GUILayout.BeginVertical("Box"); ChunkController selected = chunkControllers[_selectedIndex]; Editor editor = CreateEditor(selected); editor.OnInspectorGUI(); GUILayout.EndVertical(); } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Returns the TileController that exists within the Chunk specified in the tile position specified /// </summary> /// <param name="chunkPosition">The Chunk position specified in Chunk coordinates (not world co-ordinates)</param> /// <param name="tilePosition">The tile position specified relative to the chunk (0 to Chunk.SIZE(-1))</param> /// <returns></returns> public TileController this[Vector2Int chunkPosition, Vector2Int tilePosition] { get { // Find the the ChunkController in the collection with the chunk position specified ChunkController chunkController = ChunkControllers.Find(c => c.Chunk != null && c.Chunk.Position == chunkPosition); if (chunkController != null) { return(chunkController[tilePosition]); } return(null); } }
private IEnumerator UpdateChunkControllers(List <Chunk> chunksToDisplay) { // 1. Get a collection of the chunks needed displaying // 2. Remove chunks that are already being displayed from both the // chunk controllers collection and needed to display collection // 3. Loop through the remaining controllers and assign a chunk from // the need to display collection List <ChunkController> chunkControllersToSet = new List <ChunkController>(ChunkControllers); for (int i = chunkControllersToSet.Count - 1; i >= 0; --i) { if (chunkControllersToSet[i].Chunk == null || !chunksToDisplay.Contains(chunkControllersToSet[i].Chunk)) { continue; } chunksToDisplay.Remove(chunkControllersToSet[i].Chunk); chunkControllersToSet.RemoveAt(i); } for (int i = 0; i < chunksToDisplay.Count; i++) { if (chunksToDisplay[i].IsInitialised) { chunkControllersToSet[i].SetChunk(chunksToDisplay[i], World); yield return(null); } else { ChunkController chunkController = chunkControllersToSet[i]; chunksToDisplay[i].OnInitialise += (chunk) => { chunkController.SetChunk(chunk, World); }; } } Debug.Log("[WorldController] - UpdateChunkControllers(List<Chunk>, List<Vector2>)"); }