コード例 #1
0
        private void ShowTileMapInfo()
        {
            EditorGUIUtility.labelWidth = 120;
            TileMapData item = tilemapData[tileMaptoolbarOption];

            if (GUILayout.Button("-", GUILayout.Width(30)))
            {
                if (EditorUtility.DisplayDialog("提示", "确定要删除 " + item.TilemapName + " 吗?", "确定", "取消"))
                {
                    tilemapData.Remove(item);
                    tileMaptoolbarOption = 0;
                }
            }
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            string[] StrlayersPopupSize = new string[SortingLayer.layers.Length];
            int[]    intlayersPopupSize = new int[SortingLayer.layers.Length];
            for (int i = 0; i < intlayersPopupSize.Length; i++)
            {
                intlayersPopupSize[i] = i;
                StrlayersPopupSize[i] = SortingLayer.layers[i].name;
            }
            string[] SortOrderPopupSize    = { TilemapRenderer.SortOrder.BottomLeft.ToString(), TilemapRenderer.SortOrder.BottomRight.ToString(), TilemapRenderer.SortOrder.TopLeft.ToString(), TilemapRenderer.SortOrder.TopRight.ToString() };
            int[]    intSortOrderPopupSize = { (int)TilemapRenderer.SortOrder.BottomLeft, (int)TilemapRenderer.SortOrder.BottomRight, (int)TilemapRenderer.SortOrder.TopLeft, (int)TilemapRenderer.SortOrder.TopRight };

            item.TilemapName       = EditorGUILayout.TextField("TileMap Name : ", item.TilemapName, GUILayout.Width(250));
            item.SortOrderIndex    = EditorGUILayout.IntPopup("Sort Order:", item.SortOrderIndex, SortOrderPopupSize, intSortOrderPopupSize, GUILayout.ExpandWidth(true), GUILayout.Width(250));
            item.SortingLayerIndex = EditorGUILayout.IntPopup("Sorting Layer:", item.SortingLayerIndex, StrlayersPopupSize, intlayersPopupSize, GUILayout.ExpandWidth(true), GUILayout.Width(250));
            item.OrderInLayer      = EditorGUILayout.IntField("Order in Layer : ", item.OrderInLayer, GUILayout.Width(250));
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            if (GUILayout.Button("预  览", GUILayout.Width(100)))
            {
                CreateCurTileMap();
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            if (item.tileInfoList == null)
            {
                GUILayout.Label("Tile Count : 0");
            }
            else
            {
                GUILayout.Label("Tile Count : " + item.tileInfoList.Count);
            }

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            if (item.tileInfoList != null)
            {
                for (int i = 0; i < item.tileInfoList.Count; i++)
                {
                    XMTile tile = (XMTile)item.tileInfoList[i].tile;
                    GUILayout.Label("【" + (i + 1).ToString("0000") + "】   walkable:" + tile.walkable + "      destroable:" + tile.destroable + "      Pos:" + item.tileInfoList[i].pos + "      Tile:" + tile);
                }
            }
            EditorGUILayout.EndScrollView();
        }
コード例 #2
0
        /// <summary>
        /// 添加地图数据
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="position"></param>
        private void AddTileMapData(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
        {
            TileInfo data = new TileInfo
            {
                //tile的中心点为四个顶点的其中一个点,默认左下角,我们偏移一下保证和其他游戏对象的中心点一致,这里是还原创建Grid时的偏移,保证对象刚好在tile的中心点
                pos  = gridLayout.CellToWorld(position) + XMMapData.tileOffset3,
                ipos = position
            };

            for (int i = 0; i < cells.Length; i++)
            {
                XMTile xmtile = (XMTile)cells[i].tile;
                data.tile = xmtile;
            }
            XMMapData.AddData(brushTarget, data.pos, data);
        }