Exemplo n.º 1
0
        //void SaveCollisionMap(NavMeshData data)
        public void SaveCollisionMap(string serverPath)
        {
            List <BoundaryEdge> boundary = WG_Helper.GetNavmeshBoundary();

            if (serverPath != null)
            {
                using (StreamWriter outputFile = new StreamWriter(serverPath + @"CollisionMap.txt"))
                {
                    for (int i = 0; i < boundary.Count; i++)
                    {
                        BoundaryEdge edge = boundary[i];
                        outputFile.Write(WG_Helper.Vectro3ToString(edge.start) + "|" + WG_Helper.Vectro3ToString(edge.end) + (i == boundary.Count - 1 ? "" : "|"));
                        //IntIntClass edge = edgesList[boundaryEdges[i]].GetEdgeVertices();

                        //outputFile.Write(WG_Helper.Vectro3ToString(vertexList[edge.value1].position) + "|" + WG_Helper.Vectro3ToString(vertexList[edge.value2].position) + (i == boundaryEdges.Count - 1 ? "" : "|"));
                    }
                }
            }
        }
Exemplo n.º 2
0
        void OnDrawGizmos()
        {
            #if UNITY_EDITOR
            if (visualMap != null && visualizeMap)
            {
                for (int x = 0; x < visualMap.GetLength(0); x++)
                {
                    for (int y = 0; y < visualMap.GetLength(1); y++)
                    {
                        Gizmos.color = (visualMap[x, y]) ? new Color(0, 0, 0, gizmoAlpha) : new Color(1, 1, 1, gizmoAlpha);
                        Vector3 pos = new Vector3(-visualAreaSize / 2 + (x + 0.5f) * visualSquareSize + visualAreaCenter.position.x, 0, -visualAreaSize / 2 + (y + 0.5f) * visualSquareSize + visualAreaCenter.position.z);
                        Gizmos.DrawCube(pos, new Vector3(visualSquareSize * 0.75f, 0.0f, visualSquareSize * 0.75f));
                    }
                }

                Vector2 minCorner = new Vector2(visualAreaCenter.position.x - visualAreaSize / 2, visualAreaCenter.position.z - visualAreaSize / 2);
                Vector2 maxCorner = new Vector2(visualAreaCenter.position.x + visualAreaSize / 2, visualAreaCenter.position.z + visualAreaSize / 2);

                int minX = (int)(minCorner.x / (segmentSize / 2)) + (minCorner.x > 0 ? 1 : 0);
                int maxX = (int)(maxCorner.x / (segmentSize / 2)) + (maxCorner.x > 0 ? 1 : 0);

                int minY = (int)(minCorner.y / (segmentSize / 2)) + (minCorner.y > 0 ? 1 : 0);
                int maxY = (int)(maxCorner.y / (segmentSize / 2)) + (maxCorner.y > 0 ? 1 : 0);

                Gizmos.color = visualZoneLine;
                for (int x = minX - 1; x < maxX + 1; x++)
                {
                    for (int y = minY - 1; y < maxY + 1; y++)
                    {
                        if (x % 2 == 0 && y % 2 == 0)
                        {
                            Gizmos.DrawLine(GetPositionOfSegmetnCorner(x - 1, y - 1), GetPositionOfSegmetnCorner(x + 1, y - 1));
                            Gizmos.DrawLine(GetPositionOfSegmetnCorner(x + 1, y - 1), GetPositionOfSegmetnCorner(x + 1, y + 1));
                            Gizmos.DrawLine(GetPositionOfSegmetnCorner(x + 1, y + 1), GetPositionOfSegmetnCorner(x - 1, y + 1));
                            Gizmos.DrawLine(GetPositionOfSegmetnCorner(x - 1, y + 1), GetPositionOfSegmetnCorner(x - 1, y - 1));

                            string  labelString = "(" + (x / 2).ToString() + ", " + (y / 2).ToString() + ")";
                            Vector3 labelPos    = new Vector3(x * segmentSize / 2, 2.0f, y * segmentSize / 2);
                            Handles.Label(labelPos, labelString);
                        }
                    }
                }
            }

            if (visualizeBoundaryEdges)
            {
                List <BoundaryEdge> boundary = WG_Helper.GetNavmeshBoundary();

                Gizmos.color = boundaryLine;
                for (int i = 0; i < boundary.Count; i++)
                {
                    BoundaryEdge edge = boundary[i];
                    if (true)
                    {
                        Gizmos.DrawLine(edge.start, edge.end);
                        //Handles.DrawSolidDisc(edge.start, Vector3.up, 0.03f);
                        //Handles.Label(edge.start, edge.startVertex.ToString());
                        //Handles.DrawSolidDisc(edge.end, Vector3.up, 0.03f);
                        //Handles.Label(edge.end, edge.endVertes.ToString());
                        //Handles.Label((edge.start + edge.end) / 2.0f, edge.index.ToString());
                    }
                }
            }
            #endif
        }