Example #1
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Convert to MapInfo string.
         * @return a MapInfo MIF string.
         */
        public override string ToString()
        {
            string retStr = "REGION 1" + CRLF;

            retStr += "\t" + Region.GetVertexCount() + CRLF;
            for (int i = 0; i < Region.GetVertexCount(); i++)
            {
                GeoLatLng latLng = Region.GetVertex(i);
                retStr += latLng.X + " " + latLng.Y + CRLF;
            }
            retStr += "\t" + "PEN(" + PenStyle.Width + "," + PenStyle.Pattern + ","
                      + PenStyle.Color + ")" + CRLF;
            retStr += "\t" + "BRUSH(" + BrushStyle.Pattern + "," + BrushStyle.ForeColor + ","
                      + BrushStyle.BackColor + ")" + CRLF;
            retStr += "\tCENTER " + CenterPt.X + " " + CenterPt.Y + CRLF;
            return(retStr);
        }
Example #2
0
    public void CreateMapData()
    {
        string sceneNamePre = Application.loadedLevelName;

        string realPath = Application.dataPath + "/" + filePath + "/" + sceneNamePre + "/data/sd_" + sceneNamePre + "_" + fileName + ".bytes";


        if (File.Exists(realPath) == true)
        {
            File.Delete(realPath);
        }

        // 改用识别多边形点检测
        GeoPolygon[] pList = GameObject.FindObjectsOfType <GeoPolygon>();

        FileStream   file = new FileStream(realPath, FileMode.Create);
        BinaryWriter bw   = new BinaryWriter(file);

        bw.Write((uint)(cellCount));
        bw.Write((uint)(cellCount));

        mapData = new byte[cellCount * cellCount];

        Vector3 pos = Vector3.zero;

        pos.y = 500;
        for (int i = 0; i < cellCount; ++i)
        {
            pos.x = cellSize * i + cellSize * 0.5f;
            for (int j = 0; j < cellCount; ++j)
            {
                pos.z = cellSize * j + cellSize * 0.5f;
                //if(Physics.Raycast (pos, castDir, 1000, mask))
                //{
                //	mapData1[i * cellCount + j] = 1;
                //}
                for (int p = 0; p < pList.Length; p++)
                {
                    GeoPolygon geo = pList[p];
                    if (IsInPolygon(pos.ToVector2d(), geo.GetVertex()))
                    {
                        // 取周围8个点为障碍点
                        byte type = 1;
                        if (geo.bAirWall)
                        {
                            type = 2;
                        }
                        mapData[i * cellCount + j] = type;
                        UpdateData(i, j, 1, type);
                        //UpdateData(i, j, 2);
                        continue;
                    }
                }
            }
        }

        // 0000 0010
        // 0000 0100
        // 0000 1000
        // 0001 0000
        // var byteData = new byte[cellCount * cellCount / 4];
        // for(int i = 0; i < cellCount * cellCount; i += 4){
        //  int index = i / 4;
        //  byteData [index] |= mapData1 [i] == true ? (byte)2 : (byte)0;
        //  byteData [index] |= mapData1 [i + 1] == true ? (byte)4 : (byte)0;
        //  byteData [index] |= mapData1 [i + 2] == true? (byte)8 : (byte)0;
        //  byteData [index] |= mapData1 [i + 3] == true? (byte)16 : (byte)0;
        // }

        bw.Write(mapData);
        bw.Close();
        file.Close();
    }