public void AddTile(int x, int y, int id) { Chunk currentChunk = ManageChunkTile(x, y, id); currentChunk.SetTile(new Vector3Int(x % chunkSize, y % chunkSize, 0), tilebaseDictionary[id]); lightService.RecursivAddShadow(x, y); RefreshLight(CycleDay.GetIntensity()); RefreshChunkNeightboorTiles(x, y, currentChunk.tilemapTile); }
public void ChunckVisible(bool isVisible) { // to to rajouter un test pour ne plus passer par ici si le chunk est visible et a déjà été activé!!!!!!!!!!!!!!!!!! isChunkVisible = isVisible; if (isVisible && !alreadyVisible) { alreadyVisible = true; tc2d.enabled = true; RefreshShadowMap(CycleDay.GetIntensity()); } }
public void DeleteTile(int x, int y) { var id = tilesWorldMap[x, y]; Chunk currentChunk = ManageChunkTile(x, y, 0); currentChunk.SetTile(new Vector3Int(x % chunkSize, y % chunkSize, 0), null); lightService.RecursivDeleteShadow(x, y); RefreshLight(CycleDay.GetIntensity()); ManageItems.CreateItemOnMap(x, y, id); RefreshChunkNeightboorTiles(x, y, currentChunk.tilemapTile); }
public void DeleteItem(int posX, int posY) { if (tilesObjetMap[posX, posY].name == "item_11(Clone)") // toDo changer cette merde { lightService.RecursivDeleteLight(posX, posY, true); RefreshLight(CycleDay.GetIntensity()); } tilesObjetMap[posX, posY] = null; Destroy(tilesObjetMap[posX, posY]); ManageItems.CreateItemOnMap(posX, posY, 11); }
public void AddItem(int posX, int posY, InventoryItem item) { var id = item.config.id; // toDo faire un pool d'objet déjà instancié! var go = Instantiate((GameObject)Resources.Load("Prefabs/Items/item_" + id), new Vector3(posX + 0.5f, posY + 0.5f, 0), transform.rotation); tilesObjetMap[posX, posY] = go; if (id == 11) { lightService.RecursivAddNewLight(posX, posY, 0); RefreshLight(CycleDay.GetIntensity()); } }
private void Update() { var intensity = cycleDay.GetIntensity(); if (intensity != lastIntensity) { lastIntensity = intensity; var startX = indexX * chunkSize; var startY = indexY * chunkSize; for (var x = startX; x < startX + chunkSize; x++) { for (var y = startY; y < startY + chunkSize; y++) { var shadow = tilesShadowMap[x, y] + intensity; var light = tilesLightMap[x, y]; var walltTile = wallTilesMap[x, y]; if ((walltTile == 0 && tilesMap[x % chunkSize, y % chunkSize] == 0) || (light == 0 && shadow == 0)) { tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); } else { if (light <= shadow) { tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, light)); tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); } else { tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, shadow)); tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); } } } } } }
private void SetTilemapOpacity(Tilemap tilemapLight, Tilemap tilemapShadow, float[,] tilesShadowMap, float[,] tilesLightMap, int x, int y) { var shadow = tilesShadowMap[x, y] + cycleDay.GetIntensity(); var light = tilesLightMap[x, y]; if ((wallTilesMap[x, y] == 0 && tilesWorldMap[x, y] == 0) || (shadow == 0 && light == 0)) { tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); } else { if (light <= shadow) { tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, light)); tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); } else { tilemapShadow.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, shadow)); tilemapLight.SetColor(new Vector3Int(x, y, 0), new Color(0, 0, 0, 0)); } } }