void UpdateWater(LevelTilemap level) { if (DelayErase(level, this)) { return; } curWaterDelay -= inViewdeltaTime; if (curWaterDelay >= 0) { return; } curWaterDelay = flowSpeed; if (liquidAmount > 0) { if (CanFlowToPos(x, y - 1, level) == true) { FlowDown(x, y - 1, level, this); } else { int dir = (int)Mathf.Sign(UnityEngine.Random.Range(-1, 1)); Flow(dir, level, this); } } viewNeedUpdate = true; }
public void AddLight(LevelTilemap level, BaseLevelTile lightSource) { //lightSources.Add(lightSource.x + lightSource.y * level.sizeX, lightSource as LevelTile_Dig); light += CalcuateLight(lightSource as LevelTile_Dig); viewNeedUpdate = true; lightSource.onRemove += RemoveLight; }
protected void FillOtherLiquid(LevelTile_Dig self, LevelTile_Dig otherTile, LevelTilemap level) { int value = Mathf.Clamp(flowAmount, 0, liquidAmount); otherTile.AddWater(level, value); self.RemoveWater(level, value); }
public void RemoveLight(LevelTilemap level, BaseLevelTile lightSource) { //lightSources.Remove(lightSource.x + lightSource.y * level.sizeX); light -= CalcuateLight(lightSource as LevelTile_Dig); viewNeedUpdate = true; lightSource.onRemove -= RemoveLight; }
public void Init(LevelTilemap level) { isLoaded = false; tiles = new BaseLevelTile[chunkSize * chunkSize * chunkSize]; for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < chunkSize; y++) { tiles[x + y * chunkSize] = level.CreateTile(ToTilePosition(x, y), GetData(x, y));// new LevelTile(ToTilePosition(x, y), GetData(x,y),level); } } for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < chunkSize; y++) { var tile = GetTile(x, y); tile.Init(level, GetData(x, y), ToTilePosition(x, y)); //level.tilemap.RemoveTileFlags(ToTilePosition(x, y), TileFlags.LockColor); if (tile.HaveBehaviorUpdate()) { updateTiles.Add(tile); } if (tile.HaveBehaviorViewUpdate()) { updateTilesInView.Add(tile); } level.InitTile(tile); } } }
void CreateGrid(LevelTilemap tileMap) { nodeDiameter = 1; int minX = 0; int minY = 0; int maxX = tileMap.sizeX; int maxY = tileMap.sizeY; gridSizeX = Mathf.Abs(minX) + Mathf.Abs(maxX); gridSizeY = Mathf.Abs(minY) + Mathf.Abs(maxY); gridWorldSize.x = gridSizeX * nodeDiameter; gridWorldSize.y = gridSizeY * nodeDiameter; grid = new Node[gridSizeX, gridSizeY]; worldBottomLeft = transform.position + new Vector3(minX, minY); int indexX = 0; int indexY = 0; for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { var data = tileMap.GetITile(x, y).data; grid[indexX, indexY] = new Node(data, worldBottomLeft + new Vector3(indexX + .5f, indexY + .5f, 0), indexX, indexY, 0); indexY++; } indexX++; indexY = 0; } //BlurPenaltyMap(3); }
protected virtual void Awake() { levelTilemap = GetComponent <LevelTilemap>(); levelTilemap.onLoaded += Onloaded; levelTilemap.onLoadChunkNewMidChunk += LoadNewMidChunk; levelTilemap.onInitTile += InitTile; levelTilemap.onLoadTileFirstTime += LoadTileFirstTime; }
public override void Init(LevelTilemap map, BaseLevelTile tile) { base.Init(map, tile); if (go != null) { map.AddGameObjectToTile(tile, go); } }
public virtual Color GetColor(LevelTilemap level) { if (HaveBehavior() == false) { return(Color.white); } return(behavior.GetColor(this, level)); }
public void Update(LevelTilemap level) { for (int i = 0; i < updateTiles.Count; i++) { updateTiles[i].UpdateBehaviorTile(level); } return; }
public virtual bool OverrideColor(LevelTilemap level) { if (HaveBehavior() == false) { return(false); } return(behavior.OverrideColor(this, level)); }
public override void UpdateBehaviorInViewTile(LevelTilemap level) { base.UpdateBehaviorInViewTile(level); if (HasWater()) { UpdateWater(level); } }
public void UpdateInView(LevelTilemap level) { for (int i = 0; i < updateTilesInView.Count; i++) { updateTilesInView[i].UpdateBehaviorInViewTile(level); } level.LoadChunk(UpdateViewChunke(level)); }
public virtual void UpdateBehaviorInViewTile(LevelTilemap level) { inViewdeltaTime = Time.time - inViewlastUpdateTime; if (behavior != null) { behavior.UpdateInView(level, this, inViewdeltaTime); } inViewlastUpdateTime = Time.time; }
public virtual void LoadNewMidChunk(LevelTilemap levelTilemap, Vector2Int chunckPos, Vector3Int midChunk) { Vector3Int vec3IntTemp = Vector3Int.zero; vec3IntTemp.x = chunckPos.x - midChunk.x;//dir vec3IntTemp.y = chunckPos.y - midChunk.y; vec3IntTemp.z = 0; SetRenderTexture(vec3IntTemp.x, vec3IntTemp.y, GetRenderAllTexutre(chunckPos.x, chunckPos.y)); }
RenderTexture CreateRenderTexture(LevelTilemap levelTilemap, string name) { var r = new RenderTexture(levelTilemap.chunkSize * tileSize, levelTilemap.chunkSize * tileSize, 0); r.filterMode = FilterMode.Trilinear; r.wrapMode = TextureWrapMode.Clamp; r.name = name; return(r); }
public virtual void UpdateBehaviorTile(LevelTilemap level) { deltaTime = Time.time - lastUpdateTime; if (behavior != null) { behavior.Update(level, this, deltaTime); } lastUpdateTime = Time.time; }
public void FillWithTile(LevelTilemap level, LevelTileData data) { for (int x = 0; x < level.sizeX; x++) { for (int y = 0; y < level.sizeY; y++) { level.GetITile(x, y).OverrideData(level, data, x, y); } } }
public void FillWithDataName(LevelTilemap level, LevelTileData data) { for (int x = 0; x < level.sizeX; x++) { for (int y = 0; y < level.sizeY; y++) { level.OverrideDataNameTile(x, y, data); } } }
public virtual void Destroy(LevelTilemap level) { if (HaveBehavior()) { behavior.OnDestry(this, level); } if (go != null) { GameObject.Destroy(go.gameObject); } }
public IEnumerator UpdateViewChunke(LevelTilemap level) { for (int y = 0; y < chunkSize; y++) { for (int x = 0; x < chunkSize; x++) { level.UpdateViewTile(GetTile(x, y)); } yield return(null); } }
void FlowDown(int x, int y, LevelTilemap level, LevelTile_Dig tile) { if (CanFlowToPos(x, y, level) == false) { return; } if (liquidAmount <= 0) { return; } FillOtherLiquid(tile, level.GetTile <LevelTile_Dig>(x, y), level); }
public virtual void ApplyDamage(LevelTilemap level, TileDamageType type, int damage) { if (currentHealth == -1) { return; } currentHealth -= damage; if (currentHealth > 0) { return; } level.DestroyTile(this); }
public override void Remove(LevelTilemap level) { base.Remove(level); var digData = data as LevelTileData_Dig; if (digData == null) { return; } heat -= digData.baseHeat; light -= digData.baseLight; }
public void AddWater(LevelTilemap level, int amount) { if (HasWater()) { liquidAmount += amount; } else { liquidAmount = amount; level.GetITile(x, y - 1).viewNeedUpdate = true; } viewNeedUpdate = true; level.ChangedTile(this); }
void RemoveTile(LevelTilemap level, int x, int y) { var tile = GetTile(x, y); tile.Remove(level); if (tile.HaveBehaviorUpdate()) { updateTiles.Remove(tile); } if (tile.HaveBehaviorViewUpdate()) { updateTilesInView.Remove(tile); } }
public virtual void Remove(LevelTilemap level) { if (HaveBehavior()) { behavior.OnRemove(this, level); } if (data != null) { data.Remove(level, this); } if (onRemove != null) { onRemove(level, this); } }
// accessor functions public int[] GetPixels(Level level, Tileset tileset) { LevelTilemap tilemap = new LevelTilemap(level, tileset, this); int[] pixels = tilemap.Pixels; int[] temp = new int[size.Width * size.Height]; for (int y = 0; y < size.Height; y++) { for (int x = 0; x < size.Width; x++) { temp[y * size.Width + x] = pixels[y * 1024 + x]; } } return(temp); }
public void RemoveWater(LevelTilemap level, int amount) { if (HasWater()) { liquidAmount = Mathf.Max(liquidAmount - amount, 0); if (liquidAmount <= 0) { erase = true; delayedErase = .4f; level.GetITile(x, y - 1).viewNeedUpdate = true; } level.ChangedTile(this); } viewNeedUpdate = true; }
public override void LoadTileFirstTime(LevelTilemap levelTilemap, BaseLevelTile tile) { base.LoadTileFirstTime(levelTilemap, tile); var chunkPos = levelTilemap.PosToChunk(tile.x, tile.y); var inChunkPos = levelTilemap.PosToPosInChunk(tile.x, tile.y); var data = tile.data; var fluidData = data as IFluidData; collisionDrawer.SetInt("_CollisionTilePosX", inChunkPos.x); collisionDrawer.SetInt("_CollisionTilePosY", inChunkPos.y); collisionDrawer.SetTexture("_CollisionTex", fluidData.Collision()); var targetRT = GetRenderAllTexutre(chunkPos.x, chunkPos.y); Graphics.Blit(targetRT, chunkBufferRT, collisionDrawer); Graphics.Blit(chunkBufferRT, targetRT); }