Esempio n. 1
0
        public static MapChunk GetChunkAt(Vector3 position)
        {
            Vector2Int chunkPosition = _.CalculateChunk(position);
            string     coordinate    = ChunkRegistry.AsCoordinate(chunkPosition.x, chunkPosition.y);
            GameObject chunk         = _.loadedChunks.SearchChunk($"{Constants.MAP_CHUNK_INSTANCE_NAME}{coordinate}");

            if (chunk)
            {
                return(chunk.GetComponent <MapChunk>());
            }

            return(null);
        }
Esempio n. 2
0
 private void Awake()
 {
     if (_ == null)
     {
         _ = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
     registry = GetComponent <ChunkRegistry>();
 }
Esempio n. 3
0
        private GameObject LoadChunk(Vector2Int pos)
        {
            GameObject chunk = registry.GetChunk(new Vector2Int(pos.x, pos.y));

            if (!chunk)
            {
                return(null);
            }
            string     coordinate   = ChunkRegistry.AsCoordinate(pos.x, pos.y);
            GameObject currentChunk = Instantiate(chunk, Vector3.zero, Quaternion.identity);

            currentChunk.name = $"{Constants.MAP_CHUNK_INSTANCE_NAME}{coordinate}";


            return(currentChunk);
        }