예제 #1
0
 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;
 }
예제 #2
0
 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;
 }
예제 #3
0
    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);
    }
예제 #4
0
 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;
 }
예제 #5
0
 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);
         }
     }
 }
예제 #6
0
파일: Grid.cs 프로젝트: claudyy/TileMap
        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);
        }
예제 #7
0
 protected virtual void Awake()
 {
     levelTilemap           = GetComponent <LevelTilemap>();
     levelTilemap.onLoaded += Onloaded;
     levelTilemap.onLoadChunkNewMidChunk += LoadNewMidChunk;
     levelTilemap.onInitTile             += InitTile;
     levelTilemap.onLoadTileFirstTime    += LoadTileFirstTime;
 }
예제 #8
0
 public override void Init(LevelTilemap map, BaseLevelTile tile)
 {
     base.Init(map, tile);
     if (go != null)
     {
         map.AddGameObjectToTile(tile, go);
     }
 }
예제 #9
0
 public virtual Color GetColor(LevelTilemap level)
 {
     if (HaveBehavior() == false)
     {
         return(Color.white);
     }
     return(behavior.GetColor(this, level));
 }
예제 #10
0
 public void Update(LevelTilemap level)
 {
     for (int i = 0; i < updateTiles.Count; i++)
     {
         updateTiles[i].UpdateBehaviorTile(level);
     }
     return;
 }
예제 #11
0
 public virtual bool OverrideColor(LevelTilemap level)
 {
     if (HaveBehavior() == false)
     {
         return(false);
     }
     return(behavior.OverrideColor(this, level));
 }
예제 #12
0
 public override void UpdateBehaviorInViewTile(LevelTilemap level)
 {
     base.UpdateBehaviorInViewTile(level);
     if (HasWater())
     {
         UpdateWater(level);
     }
 }
예제 #13
0
 public void UpdateInView(LevelTilemap level)
 {
     for (int i = 0; i < updateTilesInView.Count; i++)
     {
         updateTilesInView[i].UpdateBehaviorInViewTile(level);
     }
     level.LoadChunk(UpdateViewChunke(level));
 }
예제 #14
0
 public virtual void UpdateBehaviorInViewTile(LevelTilemap level)
 {
     inViewdeltaTime = Time.time - inViewlastUpdateTime;
     if (behavior != null)
     {
         behavior.UpdateInView(level, this, inViewdeltaTime);
     }
     inViewlastUpdateTime = Time.time;
 }
예제 #15
0
    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));
    }
예제 #16
0
    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);
    }
예제 #17
0
 public virtual void UpdateBehaviorTile(LevelTilemap level)
 {
     deltaTime = Time.time - lastUpdateTime;
     if (behavior != null)
     {
         behavior.Update(level, this, deltaTime);
     }
     lastUpdateTime = Time.time;
 }
예제 #18
0
 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);
         }
     }
 }
예제 #19
0
 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);
         }
     }
 }
예제 #20
0
 public virtual void Destroy(LevelTilemap level)
 {
     if (HaveBehavior())
     {
         behavior.OnDestry(this, level);
     }
     if (go != null)
     {
         GameObject.Destroy(go.gameObject);
     }
 }
예제 #21
0
 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);
     }
 }
예제 #22
0
    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);
    }
예제 #23
0
 public virtual void ApplyDamage(LevelTilemap level, TileDamageType type, int damage)
 {
     if (currentHealth == -1)
     {
         return;
     }
     currentHealth -= damage;
     if (currentHealth > 0)
     {
         return;
     }
     level.DestroyTile(this);
 }
예제 #24
0
    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;
    }
예제 #25
0
 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);
 }
예제 #26
0
    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);
        }
    }
예제 #27
0
 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);
     }
 }
예제 #28
0
        // 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);
        }
예제 #29
0
 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;
 }
예제 #30
0
    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);
    }