示例#1
0
    static void ExportMapArea(string path, Example.MapTile[,] tiles, MapAreaSettings settings, int width, int height)
    {
        var tileList = new List <int> ();

        Example.MapTile tile = null;

        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                tile = tiles [y, x];
                if (tile != null)
                {
                    tileList.Add((int)tile.Type);
                }
                else
                {
                    tileList.Add(-1);
                }
            }
        }

        /*for (int y = 0; y < height; ++y) {
         *      for (int x = 0; x < width; ++x) {
         *              Debug.LogFormat ("x={0},y={1}",x,y);
         *              tileList [y * height + x] = tiles [y, x];
         *      }
         * }*/

        Example.MapTiles tileAll = new Example.MapTiles();
        tileAll.CellSize = settings.resolution;
        tileAll.Row      = height;
        tileAll.Column   = width;
        tileAll.Pos      = MapUtil.ToVector3f(mapBounds.min);
        tileAll.Tiles    = tileList;

        File.WriteAllBytes(path, Example.MapTiles.SerializeToBytes(tileAll));
    }
示例#2
0
    static void GenerateSceneAreas()
    {
        if (mapBounds.size.sqrMagnitude < 0.1f)
        {
            GenerateSceneConfguration();
        }

        var settings = GameObject.FindObjectOfType <MapAreaSettings> ();

        float resolution = settings.resolution;
        int   width      = Mathf.CeilToInt(mapBounds.size.x * resolution);
        int   height     = Mathf.CeilToInt(mapBounds.size.z * resolution);
        var   texture    = new Texture2D(width, height, TextureFormat.ARGB4444, false);

        Example.MapTile[,] tiles = new Example.MapTile[height, width];

        EditorUtility.DisplayProgressBar("GenerateSceneAreas", "", 0);

        float      total = (width * height);
        var        upper = mapBounds.max + Vector3.up;
        var        lower = mapBounds.min;
        RaycastHit hit;
        Color      color;

        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                upper.x = x / resolution + mapBounds.center.x - mapBounds.size.x / 2;
                upper.z = y / resolution + mapBounds.center.z - mapBounds.size.z / 2;
                if (Physics.Raycast(upper, Vector3.down, out hit, 1000, LayerMask.GetMask("Surface")))
                {
                    var sceneExt = hit.collider.GetComponent <SceneExt> ();
                    if (sceneExt != null)
                    {
                        var areaType = sceneExt.areaType;
                        var t4m      = hit.collider.gameObject.GetComponent("T4MObjSC");
                        if (t4m != null)
                        {
                            areaType = GetT4MAreaColor(settings, sceneExt, hit.textureCoord);
                        }
                        color = GetAreaColor(areaType);
                        texture.SetPixel(x, y, color);

                        var tile = new Example.MapTile();
                        tile.Type    = (Example.MapArea.Type)areaType;
                        tiles [y, x] = tile;
                    }
                    else
                    {
                        texture.SetPixel(x, y, Color.clear);
                    }
                }
                else
                {
                    texture.SetPixel(x, y, Color.clear);
                }
            }
            EditorUtility.DisplayProgressBar("GenerateSceneAreas", "line " + (y + 1) + "/" + height, (float)y / height);
        }

        EditorUtility.ClearProgressBar();

        int sceneID = MapManager.current.sceneId;

        texture.Apply();
        var data = texture.EncodeToPNG();

        File.WriteAllBytes(MapUtil.DataPath() + "MapArea_" + sceneID + ".png", data);

        ExportMapArea(MapUtil.DataPath() + "MapArea_" + sceneID + ".bytes", tiles, settings, width, height);
    }