• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# tk2dTileMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中tk2dTileMap的典型用法代码示例。如果您正苦于以下问题:C# tk2dTileMap类的具体用法?C# tk2dTileMap怎么用?C# tk2dTileMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



tk2dTileMap类属于命名空间,在下文中一共展示了tk2dTileMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DestroyColliderData

 public void DestroyColliderData(tk2dTileMap tileMap)
 {
     if (this.colliderMesh != null)
     {
         tileMap.DestroyMesh(this.colliderMesh);
     }
     if (((this.meshCollider != null) && (this.meshCollider.sharedMesh != null)) && (this.meshCollider.sharedMesh != this.colliderMesh))
     {
         tileMap.DestroyMesh(this.meshCollider.sharedMesh);
     }
     if (this.meshCollider != null)
     {
         tk2dUtil.DestroyImmediate(this.meshCollider);
     }
     this.meshCollider = null;
     this.colliderMesh = null;
     if (this.edgeColliders.Count > 0)
     {
         for (int i = 0; i < this.edgeColliders.Count; i++)
         {
             tk2dUtil.DestroyImmediate(this.edgeColliders[i]);
         }
         this.edgeColliders.Clear();
     }
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:25,代码来源:SpriteChunk.cs


示例2: Build

		public static void Build(tk2dTileMap tileMap, bool forceBuild)
		{
			bool incremental = !forceBuild;
			int numLayers = tileMap.Layers.Length;
			for (int layerId = 0; layerId < numLayers; ++layerId)
			{
				var layer = tileMap.Layers[layerId];
				if (layer.IsEmpty || !tileMap.data.Layers[layerId].generateCollider)
					continue;
	
				for (int cellY = 0; cellY < layer.numRows; ++cellY)
				{
					int baseY = cellY * layer.divY;
					for (int cellX = 0; cellX < layer.numColumns; ++cellX)
					{
						int baseX = cellX * layer.divX;
						var chunk = layer.GetChunk(cellX, cellY);
						
						if (incremental && !chunk.Dirty)
							continue;
						
						if (chunk.IsEmpty)
							continue;
						
						BuildForChunk(tileMap, chunk, baseX, baseY);

						PhysicMaterial material = tileMap.data.Layers[layerId].physicMaterial;
						if (chunk.meshCollider != null) {
							chunk.meshCollider.sharedMaterial = material;
						}
					}
				}
			}
		}
开发者ID:Eddikos,项目名称:public-access-1,代码行数:34,代码来源:tk2dTileMapColliderBuilder.cs


示例3: DrawBrush

        public Rect DrawBrush(tk2dTileMap tileMap, tk2dTileMapEditorBrush brush, float scale, bool forceUnitSpacing, int tilesPerRow)
        {
            var dictData = GetDictDataForBrush(brush, tilesPerRow);
            Mesh atlasViewMesh = dictData.mesh;
            Rect atlasViewRect = BrushToScreenRect(dictData.rect);

            float width = atlasViewRect.width * scale;
            float height = atlasViewRect.height * scale;

            float maxScreenWidth = Screen.width - 16;
            if (width > maxScreenWidth)
            {
                height = height * maxScreenWidth / width;
                width = maxScreenWidth;
            }

            Rect rect = GUILayoutUtility.GetRect(width, height, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false));
            scale = width / atlasViewRect.width;
            lastScale = scale;

            if (Event.current.type == EventType.Repaint)
            {
                tileMap.spriteCollection.materials[0].SetPass(0);
                Matrix4x4 mat = new Matrix4x4();
                var spriteDef = tileMap.spriteCollection.spriteDefinitions[0];
                mat.SetTRS(new Vector3(rect.x,
                                       rect.y + height, 0), Quaternion.identity, new Vector3(scale / spriteDef.texelSize.x, -scale / spriteDef.texelSize.y, 1));
                Graphics.DrawMeshNow(atlasViewMesh, mat * GUI.matrix);
            }

            return rect;
        }
开发者ID:britg,项目名称:Pyroclasm,代码行数:32,代码来源:tk2dTileMapBrushRenderer.cs


示例4: AddNewLayer

        // Returns index of newly added layer
        public static int AddNewLayer(tk2dTileMap tileMap)
        {
            var existingLayers = tileMap.data.Layers;
            // find a unique hash
            bool duplicateHash = false;
            int hash;
            do
            {
                duplicateHash = false;
                hash = Random.Range(0, int.MaxValue);
                foreach (var layer in existingLayers)
                    if (layer.hash == hash)
                        duplicateHash = true;
            } while (duplicateHash == true);

            var newLayer = new tk2dRuntime.TileMap.LayerInfo();
            newLayer.name = "New Layer";
            newLayer.hash = hash;
            newLayer.z = 0.1f;
            tileMap.data.tileMapLayers.Add(newLayer);

            // remap tilemap
            tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);

            return tileMap.data.NumLayers - 1;
        }
开发者ID:hyf042,项目名称:BakeryGirl-chess,代码行数:27,代码来源:tk2dTileMapUtility.cs


示例5: Import

        ////////////////////////////////////////////////////////////////////////////////////////////////
        /// Static and helper functions
        ////////////////////////////////////////////////////////////////////////////////////////////////
        public static bool Import(tk2dTileMap tileMap, Format format)
        {
            var importer = new Importer();

            string ext = "";
            switch (format)
            {
                case Format.TMX:
                    if (!importer.CheckZlib()) return false;
                    ext = "tmx";
                break;
            }

            string path = EditorUtility.OpenFilePanel("Import tilemap", "", ext);
            if (path.Length == 0)
                return false;

            string message = "";
            switch (format)
            {
            case Format.TMX: message = importer.ImportTMX(path); break;
            }

            if (message.Length != 0)
            {
                EditorUtility.DisplayDialog("Tilemap failed to import", message, "Ok");
                return false;
            }

            importer.PopulateTilemap(tileMap);
            return true;
        }
开发者ID:Gahzi,项目名称:BrutalArena,代码行数:35,代码来源:tk2dTileMapImporter.cs


示例6: Build

        public static void Build(tk2dTileMap tileMap)
        {
            int numLayers = tileMap.Layers.Length;
            for (int layerId = 0; layerId < numLayers; ++layerId)
            {
                var layer = tileMap.Layers[layerId];
                if (layer.IsEmpty || !tileMap.data.Layers[layerId].generateCollider)
                    continue;

                for (int cellY = 0; cellY < layer.numRows; ++cellY)
                {
                    int baseY = cellY * layer.divY;
                    for (int cellX = 0; cellX < layer.numColumns; ++cellX)
                    {
                        int baseX = cellX * layer.divX;
                        var chunk = layer.GetChunk(cellX, cellY);

                        if (chunk.IsEmpty)
                            continue;

                        BuildForChunk(tileMap, chunk, baseX, baseY);
                    }
                }
            }
        }
开发者ID:hyf042,项目名称:BakeryGirl-chess,代码行数:25,代码来源:tk2dTileMapColliderBuilder.cs


示例7: BuildForChunk

		public static void BuildForChunk(tk2dTileMap tileMap, SpriteChunk chunk, int baseX, int baseY)
		{
			// Build local mesh
			Vector3[] localMeshVertices = new Vector3[0];
			int[] localMeshIndices = new int[0];
			BuildLocalMeshForChunk(tileMap, chunk, baseX, baseY, ref localMeshVertices, ref localMeshIndices);
			
			// only process when there are more than two triangles
			// avoids a lot of branches later
			if (localMeshIndices.Length > 6) 
			{
				// Remove duplicate verts
				localMeshVertices = WeldVertices(localMeshVertices, ref localMeshIndices);
				
				// Remove duplicate and back-to-back faces
				// Removes inside faces
				localMeshIndices = RemoveDuplicateFaces(localMeshIndices);
	
				// Merge coplanar faces
				// Optimize (remove unused vertices, reindex)
			}
	
#if !(UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
			foreach (EdgeCollider2D c2d in chunk.edgeColliders) {
				if (c2d != null) {
					tk2dUtil.DestroyImmediate(c2d);
				}
			}
			chunk.edgeColliders.Clear();
#endif

			if (localMeshVertices.Length > 0)
			{
				if (chunk.colliderMesh != null)
				{
					tk2dUtil.DestroyImmediate(chunk.colliderMesh);
					chunk.colliderMesh = null;
				}
				
				if (chunk.meshCollider == null)
				{
					chunk.meshCollider = chunk.gameObject.GetComponent<MeshCollider>();
					if (chunk.meshCollider == null)
						chunk.meshCollider = tk2dUtil.AddComponent<MeshCollider>(chunk.gameObject);
				}
				
				chunk.colliderMesh = tk2dUtil.CreateMesh();
				chunk.colliderMesh.vertices = localMeshVertices;
				chunk.colliderMesh.triangles = localMeshIndices;

				chunk.colliderMesh.RecalculateBounds();
				
				chunk.meshCollider.sharedMesh = chunk.colliderMesh;
			}
			else
			{
				chunk.DestroyColliderData(tileMap);
			}
		}		
开发者ID:Eddikos,项目名称:public-access-1,代码行数:59,代码来源:tk2dTileMapColliderBuilder.cs


示例8: ResizeTileMap

        public static void ResizeTileMap(tk2dTileMap tileMap, int width, int height, int partitionSizeX, int partitionSizeY)
        {
            int w = Mathf.Clamp(width, 1, MaxWidth);
            int h = Mathf.Clamp(height, 1, MaxHeight);

            tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);

            // copy into new tilemap
            Layer[] layers = new Layer[tileMap.Layers.Length];
            for (int layerId = 0; layerId < tileMap.Layers.Length; ++layerId)
            {
                var srcLayer = tileMap.Layers[layerId];
                layers[layerId] = new Layer(srcLayer.hash, width, height, partitionSizeX, partitionSizeY);
                var destLayer = layers[layerId];

                if (srcLayer.IsEmpty)
                    continue;

                int hcopy = Mathf.Min(tileMap.height, h);
                int wcopy = Mathf.Min(tileMap.width, w);

                for (int y = 0; y < hcopy; ++y)
                {
                    for (int x = 0; x < wcopy; ++x)
                    {
                        destLayer.SetTile(x, y, srcLayer.GetTile(x, y));
                    }
                }

                destLayer.Optimize();
            }

            // copy new colors
            bool copyColors = (tileMap.ColorChannel != null && !tileMap.ColorChannel.IsEmpty);
            ColorChannel targetColors = new ColorChannel(width, height, partitionSizeX, partitionSizeY);
            if (copyColors)
            {
                int hcopy = Mathf.Min(tileMap.height, h) + 1;
                int wcopy = Mathf.Min(tileMap.width, w) + 1;
                for (int y = 0; y < hcopy; ++y)
                {
                    for (int x = 0; x < wcopy; ++x)
                    {
                        targetColors.SetColor(x, y, tileMap.ColorChannel.GetColor(x, y));
                    }
                }

                targetColors.Optimize();
            }

            tileMap.ColorChannel = targetColors;
            tileMap.Layers = layers;
            tileMap.width = w;
            tileMap.height = h;
            tileMap.partitionSizeX = partitionSizeX;
            tileMap.partitionSizeY = partitionSizeY;

            tk2dRuntime.TileMap.BuilderUtil.CleanRenderData(tileMap);
        }
开发者ID:hyf042,项目名称:BakeryGirl-chess,代码行数:59,代码来源:tk2dTileMapUtility.cs


示例9: MoveLayer

 public static void MoveLayer(tk2dTileMap tileMap, int layer, int direction)
 {
     tk2dRuntime.TileMap.BuilderUtil.CleanRenderData(tileMap);
     var tmp = tileMap.data.tileMapLayers[layer];
     tileMap.data.tileMapLayers[layer] = tileMap.data.tileMapLayers[layer + direction];
     tileMap.data.tileMapLayers[layer + direction] = tmp;
     tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);
 }
开发者ID:hyf042,项目名称:BakeryGirl-chess,代码行数:8,代码来源:tk2dTileMapUtility.cs


示例10: DestroyGameData

		public void DestroyGameData(tk2dTileMap tileMap)
		{
			if (mesh != null) tileMap.DestroyMesh(mesh);
			if (gameObject != null) GameObject.DestroyImmediate(gameObject);
			gameObject = null;
			mesh = null;
			
			DestroyColliderData(tileMap);
		}
开发者ID:Kasfan,项目名称:ChainJamGame,代码行数:9,代码来源:tk2dTileMapChunks.cs


示例11: DestroyColliderData

		public void DestroyColliderData(tk2dTileMap tileMap)
		{
			if (colliderMesh != null) 
				tileMap.DestroyMesh(colliderMesh);
			if (meshCollider != null && meshCollider.sharedMesh != null && meshCollider.sharedMesh != colliderMesh) 
				tileMap.DestroyMesh(meshCollider.sharedMesh);
			if (meshCollider != null) GameObject.DestroyImmediate(meshCollider);
			meshCollider = null;
			colliderMesh = null;
		}
开发者ID:Kasfan,项目名称:ChainJamGame,代码行数:10,代码来源:tk2dTileMapChunks.cs


示例12: DeleteLayer

        public static void DeleteLayer(tk2dTileMap tileMap, int layerToDelete)
        {
            // Just in case
            if (tileMap.data.NumLayers <= 1)
                return;

            tk2dRuntime.TileMap.BuilderUtil.CleanRenderData(tileMap);
            tileMap.data.tileMapLayers.RemoveAt(layerToDelete);
            tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);
        }
开发者ID:hyf042,项目名称:BakeryGirl-chess,代码行数:10,代码来源:tk2dTileMapUtility.cs


示例13: Build

 public static void Build(tk2dTileMap tileMap, bool editMode, bool forceBuild)
 {
     bool skipPrefabs = !editMode;
     bool flag2 = !forceBuild;
     int numLayers = tileMap.data.NumLayers;
     for (int i = 0; i < numLayers; i++)
     {
         Layer layer = tileMap.Layers[i];
         if (!layer.IsEmpty)
         {
             LayerInfo info = tileMap.data.Layers[i];
             bool useColor = !tileMap.ColorChannel.IsEmpty && tileMap.data.Layers[i].useColor;
             bool useSortingLayers = tileMap.data.useSortingLayers;
             for (int j = 0; j < layer.numRows; j++)
             {
                 int baseY = j * layer.divY;
                 for (int k = 0; k < layer.numColumns; k++)
                 {
                     int baseX = k * layer.divX;
                     SpriteChunk chunk = layer.GetChunk(k, j);
                     ColorChunk colorChunk = tileMap.ColorChannel.GetChunk(k, j);
                     bool flag5 = (colorChunk != null) && colorChunk.Dirty;
                     if ((!flag2 || flag5) || chunk.Dirty)
                     {
                         if (chunk.mesh != null)
                         {
                             chunk.mesh.Clear();
                         }
                         if (!chunk.IsEmpty)
                         {
                             if (editMode || (!editMode && !info.skipMeshGeneration))
                             {
                                 BuildForChunk(tileMap, chunk, colorChunk, useColor, skipPrefabs, baseX, baseY);
                                 if ((chunk.gameObject != null) && useSortingLayers)
                                 {
                                     Renderer renderer = chunk.gameObject.renderer;
                                     if (renderer != null)
                                     {
                                         renderer.sortingLayerName = info.sortingLayerName;
                                         renderer.sortingOrder = info.sortingOrder;
                                     }
                                 }
                             }
                             if (chunk.mesh != null)
                             {
                                 tileMap.TouchMesh(chunk.mesh);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:54,代码来源:RenderMeshBuilder.cs


示例14: GetExistingTilePrefabInstance

		static GameObject GetExistingTilePrefabInstance(tk2dTileMap tileMap, int tileX, int tileY, int tileLayer) {
			int n = tileMap.GetTilePrefabsListCount();
			for (int i = 0; i < n; ++i) {
				int x, y, layer;
				GameObject instance;
				tileMap.GetTilePrefabsListItem(i, out x, out y, out layer, out instance);
				if (x == tileX && y == tileY && layer == tileLayer)
					return instance;
			}
			return null;
		}
开发者ID:Eddikos,项目名称:public-access-1,代码行数:11,代码来源:tk2dTileMapBuilderUtil.cs


示例15: DestroyGameData

 public void DestroyGameData(tk2dTileMap tilemap)
 {
     foreach (SpriteChunk chunk in this.spriteChannel.chunks)
     {
         if (chunk.HasGameData)
         {
             chunk.DestroyColliderData(tilemap);
             chunk.DestroyGameData(tilemap);
         }
     }
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:11,代码来源:Layer.cs


示例16: BuildForChunk

        public static void BuildForChunk(tk2dTileMap tileMap, SpriteChunk chunk)
        {
            // Build local mesh
            Vector3[] localMeshVertices = new Vector3[0];
            int[] localMeshIndices = new int[0];
            BuildLocalMeshForChunk(tileMap, chunk, ref localMeshVertices, ref localMeshIndices);

            // only process when there are more than two triangles
            // avoids a lot of branches later
            if (localMeshIndices.Length > 6)
            {
                // Remove duplicate verts
                localMeshVertices = WeldVertices(localMeshVertices, ref localMeshIndices);

                // Remove duplicate and back-to-back faces
                // Removes inside faces
                localMeshIndices = RemoveDuplicateFaces(localMeshIndices);

                // Merge coplanar faces
                // Optimize (remove unused vertices, reindex)
            }

            if (localMeshVertices.Length > 0)
            {
                if (chunk.colliderMesh != null)
                {
                    GameObject.DestroyImmediate(chunk.colliderMesh);
                    chunk.colliderMesh = null;
                }

                if (chunk.meshCollider == null)
                {
                    chunk.meshCollider = chunk.gameObject.GetComponent<MeshCollider>();
                    if (chunk.meshCollider == null)
                        chunk.meshCollider = chunk.gameObject.AddComponent<MeshCollider>();
                }

                chunk.colliderMesh = tileMap.GetOrCreateMesh();
                chunk.colliderMesh.vertices = localMeshVertices;
                chunk.colliderMesh.triangles = localMeshIndices;

                chunk.colliderMesh.RecalculateBounds();
                if (tileMap.serializeRenderData)
                    chunk.mesh.RecalculateNormals();

                chunk.meshCollider.sharedMesh = chunk.colliderMesh;
            }
            else
            {
                chunk.DestroyColliderData(tileMap);
            }
        }
开发者ID:britg,项目名称:Pyroclasm,代码行数:52,代码来源:tk2dTileMapColliderBuilder.cs


示例17: FindOrCreateLayer

 public static int FindOrCreateLayer(tk2dTileMap tileMap, string name)
 {
     int index = 0;
     foreach (var v in tileMap.data.Layers)
     {
         if (v.name == name)
             return index;
         ++index;
     }
     index = AddNewLayer(tileMap);
     tileMap.data.Layers[index].name = name;
     return index;
 }
开发者ID:hyf042,项目名称:BakeryGirl-chess,代码行数:13,代码来源:tk2dTileMapUtility.cs


示例18: Awake

    /* Farseer user data string to give to each box collider fixture. */
    //private string userData = "Environment"; // TODO: implement.
    /* Farseer user tag string to give to each box collider fixture. */
    //private string userTag = "Environment"; // TODO: implement.
    /* This is called first in the Unity execution order of events, adding new Farseer colliders
     * to the tilemap before the Farseer physics engine begins. */
    void Awake()
    {
        tilemap = GetComponent<tk2dTileMap>();
        spriteDefinitions = tilemap.SpriteCollectionInst.spriteDefinitions;

        tileWidth = tilemap.data.tileSize.x;
        tileHeight = tilemap.data.tileSize.y;

        maxTilesY = Mathf.Min(tilemap.partitionSizeY, tilemap.height);
        maxTilesX = Mathf.Min(tilemap.partitionSizeX, tilemap.width);

        GenerateColliders();
    }
开发者ID:rllamas,项目名称:Quantum,代码行数:19,代码来源:GenerateTilemapColliders.cs


示例19: tk2dTileMapSceneGUI

    public tk2dTileMapSceneGUI(ITileMapEditorHost host, tk2dTileMap tileMap, tk2dTileMapEditorData editorData)
    {
        this.host = host;
        this.tileMap = tileMap;
        this.editorData = editorData;
        this.tileMapData = tileMap.data;

        // create default brush
        if (tileMap.spriteCollection && this.editorData)
        {
            this.editorData.InitBrushes(tileMap.spriteCollection);
            EditorUtility.SetDirty(this.editorData);
        }
    }
开发者ID:nbolabs,项目名称:StreetNinja,代码行数:14,代码来源:tk2dTileMapSceneGUI.cs


示例20: DestroyGameData

 public void DestroyGameData(tk2dTileMap tileMap)
 {
     if (this.mesh != null)
     {
         tileMap.DestroyMesh(this.mesh);
     }
     if (this.gameObject != null)
     {
         tk2dUtil.DestroyImmediate(this.gameObject);
     }
     this.gameObject = null;
     this.mesh = null;
     this.DestroyColliderData(tileMap);
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:14,代码来源:SpriteChunk.cs



注:本文中的tk2dTileMap类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# tk2dUIItem类代码示例发布时间:2022-05-24
下一篇:
C# tk2dSpriteCollectionDefinition类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap