Example #1
0
    /// <summary>
    /// 国战创建一个地图层
    /// </summary>
    /// <param name="parent">父Transform节点</param>
    /// <param name="lJMapLayer">层的数据对象</param>
    /// <param name="baseTileConfig">图块对象</param>
    /// <param name="mapDefaultTilemapMat">地图所用的材质球</param>
    /// <param name="renderMode">0 Chunk 1 Individual </param>
    /// <returns>返回一个tilemap</returns>
    public static UnityEngine.Tilemaps.Tilemap CreateLayerByNation(Transform parent, LJTilemaps.LJMapLayer lJMapLayer,
                                                                   LJTilemaps.LJBaseTileConfig baseTileConfig, Material mapDefaultTilemapMat, int renderMode)
    {
        GameObject layerGameObj = new GameObject(lJMapLayer.layerName);

        UnityEngine.Tilemaps.Tilemap         tilemap         = layerGameObj.AddComponent <UnityEngine.Tilemaps.Tilemap>();
        UnityEngine.Tilemaps.TilemapRenderer tilemapRenderer = layerGameObj.AddComponent <UnityEngine.Tilemaps.TilemapRenderer>();
        Transform layerTran = layerGameObj.transform;

        layerTran.SetParent(parent);
        layerTran.position   = lJMapLayer.worldPosition;
        tilemapRenderer.mode = (UnityEngine.Tilemaps.TilemapRenderer.Mode)renderMode;
        //tilemapRenderer.mode = UnityEngine.Tilemaps.TilemapRenderer.Mode.Chunk;//合并DC模式 0
        //tilemapRenderer.mode = UnityEngine.Tilemaps.TilemapRenderer.Mode.Individual;// 测试模式 1
        tilemapRenderer.sortingOrder   = lJMapLayer.orderInLayer;
        tilemapRenderer.sortingLayerID = lJMapLayer.sortingLayer;
        tilemap.origin            = lJMapLayer.origin;
        tilemap.size              = lJMapLayer.size;
        tilemap.orientation       = lJMapLayer.orientation;
        tilemap.orientationMatrix = lJMapLayer.orientationMatrix;

        if (mapDefaultTilemapMat != null)
        {
            tilemapRenderer.sharedMaterial = mapDefaultTilemapMat;
        }
        if (baseTileConfig == null)
        {
            return(tilemap);
        }
        List <LJTilemaps.LJTileData> tileDatas = lJMapLayer.tileDatas;

        for (int i = 0, imax = tileDatas.Count; i < imax; i++)
        {
            LJTilemaps.LJTileData v = tileDatas[i];
            if (v.tileId < 0)
            {
            }
            else
            {
                UnityEngine.Tilemaps.TileBase tileBase = baseTileConfig.GetTileBaseById(v.tileId);
                if (tileBase != null)
                {
                    tilemap.SetTile(v.position, tileBase);
                }
            }
        }
        tilemap.CompressBounds();
        return(tilemap);
    }
Example #2
0
 static int GetMapTile(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Game obj = (Game)ToLua.CheckObject <Game>(L, 1);
         UnityEngine.Vector3           arg0 = ToLua.ToVector3(L, 2);
         UnityEngine.Tilemaps.TileBase o    = obj.GetMapTile(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #3
0
 static int SwapTile(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.Tilemaps.Tilemap  obj  = (UnityEngine.Tilemaps.Tilemap)ToLua.CheckObject(L, 1, typeof(UnityEngine.Tilemaps.Tilemap));
         UnityEngine.Tilemaps.TileBase arg0 = (UnityEngine.Tilemaps.TileBase)ToLua.CheckObject <UnityEngine.Tilemaps.TileBase>(L, 2);
         UnityEngine.Tilemaps.TileBase arg1 = (UnityEngine.Tilemaps.TileBase)ToLua.CheckObject <UnityEngine.Tilemaps.TileBase>(L, 3);
         obj.SwapTile(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #4
0
 static int ContainsTile(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.Tilemaps.Tilemap  obj  = (UnityEngine.Tilemaps.Tilemap)ToLua.CheckObject(L, 1, typeof(UnityEngine.Tilemaps.Tilemap));
         UnityEngine.Tilemaps.TileBase arg0 = (UnityEngine.Tilemaps.TileBase)ToLua.CheckObject <UnityEngine.Tilemaps.TileBase>(L, 2);
         bool o = obj.ContainsTile(arg0);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #5
0
    static int GetEditorPreviewTile(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            UnityEngine.Tilemaps.Tilemap obj  = (UnityEngine.Tilemaps.Tilemap)ToLua.CheckObject(L, 1, typeof(UnityEngine.Tilemaps.Tilemap));
            UnityEngine.Vector3Int       arg0 = StackTraits <UnityEngine.Vector3Int> .Check(L, 2);

            UnityEngine.Tilemaps.TileBase o = obj.GetEditorPreviewTile(arg0);
            ToLua.Push(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #6
0
    static int EditorPreviewFloodFill(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 3);
            UnityEngine.Tilemaps.Tilemap obj  = (UnityEngine.Tilemaps.Tilemap)ToLua.CheckObject(L, 1, typeof(UnityEngine.Tilemaps.Tilemap));
            UnityEngine.Vector3Int       arg0 = StackTraits <UnityEngine.Vector3Int> .Check(L, 2);

            UnityEngine.Tilemaps.TileBase arg1 = (UnityEngine.Tilemaps.TileBase)ToLua.CheckObject <UnityEngine.Tilemaps.TileBase>(L, 3);
            obj.EditorPreviewFloodFill(arg0, arg1);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        Tilemap map = this.GetComponent <Tilemap>();

        //Vector3Int cellPosition = map.WorldToCell(transform.position);
        Vector3Int cellPosition = new Vector3Int(
            Mathf.RoundToInt(transform.position.x),
            Mathf.RoundToInt(transform.position.y),
            Mathf.RoundToInt(transform.position.z)
            );

        UnityEngine.Tilemaps.TileBase tile = map.GetTile(cellPosition);

        string tiletype = map.GetTile(cellPosition).name;

        Debug.Log("Collision: " + tiletype, gameObject);
    }
    //
    public void AttackHit(Damager damager)
    {
        OnAttackHit(damager);

        //for (int i = 0; i < m_SlashHitResults.Length; i++)
        //{
        //    m_SlashHitResults[i] = new RaycastHit2D();
        //}

        //Physics2D.Raycast(transform.position, m_SpriteRenderer.flipX ? Vector2.left : Vector2.right, damager.GetContactFilter(), m_SlashHitResults);
        //VFXController.Instance.Trigger(m_HashSlashHitEffect, slashContactTransform.position, 0, false, null);

        if (slashHitAudioPlayer)
        {
            UnityEngine.Tilemaps.TileBase surfaceHit = PhysicsHelper.FindTileForOverride(damager.LastHit, slashContactTransform.position, m_SpriteRenderer.flipX ? Vector2.left : Vector2.right);

            slashHitAudioPlayer.PlayRandomSound(surfaceHit);
        }
    }
Example #9
0
    static int BoxFill(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 7);
            UnityEngine.Tilemaps.Tilemap obj  = (UnityEngine.Tilemaps.Tilemap)ToLua.CheckObject(L, 1, typeof(UnityEngine.Tilemaps.Tilemap));
            UnityEngine.Vector3Int       arg0 = StackTraits <UnityEngine.Vector3Int> .Check(L, 2);

            UnityEngine.Tilemaps.TileBase arg1 = (UnityEngine.Tilemaps.TileBase)ToLua.CheckObject <UnityEngine.Tilemaps.TileBase>(L, 3);
            int arg2 = (int)LuaDLL.luaL_checknumber(L, 4);
            int arg3 = (int)LuaDLL.luaL_checknumber(L, 5);
            int arg4 = (int)LuaDLL.luaL_checknumber(L, 6);
            int arg5 = (int)LuaDLL.luaL_checknumber(L, 7);
            obj.BoxFill(arg0, arg1, arg2, arg3, arg4, arg5);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #10
0
        public MapTiler(Map map)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            this.map = map;

            sw.Start();
            this.layout = CreateGridLayout();

            var material   = map.game.assets.spriteMaterial;
            var bounds     = new BoundsInt(0, 0, 0, map.size.x * 2, map.size.y * 2, 1);
            var tileBuffer = new TM.TileBase[bounds.size.x * bounds.size.y];

            /*tilemapTerrain =*/ new Tilemap <VirtualTileTerrainBase>(map, layout, material, RenderLayer.Default.Layer(0), bounds, tileBuffer);
            tilemapTerrainOver  = new Tilemap <VirtualTileTerrainOver>(map, layout, material, RenderLayer.Default.Layer(1), bounds, tileBuffer);
            tilemapBuilding     = new Tilemap <VirtualTileBuilding>(map, layout, material, RenderLayer.Default.Layer(2), bounds, tileBuffer);
            tilemapBuildingOver = new Tilemap <VirtualTileBuildingOver>(map, layout, material, RenderLayer.OverMap.Layer(0), bounds, tileBuffer);

            sw.Stop();
            BB.LogInfo("Tilemap generation took " + sw.ElapsedMilliseconds + "ms");
        }
Example #11
0
 public void SetTile(Vector3Int position, TileBase tile)
 {
     SetTileAsset(position, tile);
 }
Example #12
0
 public bool ContainsTile(TileBase tileAsset)
 {
     return(ContainsTileAsset(tileAsset));
 }
Example #13
0
 public void FloodFill(Vector3Int position, TileBase tile)
 {
     FloodFillTileAsset(position, tile);
 }
Example #14
0
 public void BoxFill(Vector3Int position, TileBase tile, int startX, int startY, int endX, int endY)
 {
     BoxFillTileAsset(position, tile, startX, startY, endX, endY);
 }
Example #15
0
 public void SetEditorPreviewTile(Vector3Int position, TileBase tile)
 {
     SetEditorPreviewTileAsset(position, tile);
 }
Example #16
0
 public void EditorPreviewFloodFill(Vector3Int position, TileBase tile)
 {
     EditorPreviewFloodFillTileAsset(position, tile);
 }
Example #17
0
 public void SwapTile(TileBase changeTile, TileBase newTile)
 {
     SwapTileAsset(changeTile, newTile);
 }
Example #18
0
        private bool TileValue(ITilemap tileMap, Vector3Int position)
        {
            TileBase tile = tileMap.GetTile(position);

            return(tile != null && tile == this);
        }