MenuScan() private method

private MenuScan ( ) : void
return void
Exemplo n.º 1
0
 /// <summary>
 /// Editor only!!!
 /// </summary>
 public static void CreateGraphIfItNull(AstarPath path)
 {
     if (path == null)
     {
         Debug.LogWarning("AstarPath not found");
         return;
     }
     if (path.astarData == null || path.astarData.gridGraph == null)
     {
         AstarPath.MenuScan();
     }
 }
Exemplo n.º 2
0
    /** Exports the INavmesh graph to a file */
    public void ExportToFile(NavGraph target)
    {
        INavmesh graph = (INavmesh)target;

        if (graph == null)
        {
            return;
        }

        Int3[] vertices = graph.vertices;

        if (vertices == null || target.nodes == null)
        {
            if (EditorUtility.DisplayDialog("Scan graph before exporting?", "The graph does not contain any mesh data. Do you want to scan it?", "Ok", "Cancel"))
            {
                AstarPath.MenuScan();
            }
            else
            {
                return;
            }
        }

        vertices = graph.vertices;

        if (vertices == null || target.nodes == null)
        {
            Debug.LogError("Graph still does not contain any nodes or vertices. Canceling");
            return;
        }

        string path = EditorUtility.SaveFilePanel("Export .obj", "", "navmesh.obj", "obj");

        if (path == "")
        {
            return;
        }

        //Generate .obj
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        string name = System.IO.Path.GetFileNameWithoutExtension(path);

        sb.Append("g ").Append(name).AppendLine();

        //Write vertices
        for (int i = 0; i < vertices.Length; i++)
        {
            Vector3 v = (Vector3)vertices[i];
            sb.Append(string.Format("v {0} {1} {2}\n", -v.x, v.y, v.z));
        }

        //Define single texture coordinate to zero
        sb.Append("vt 0\n");

        //Write triangles
        for (int i = 0; i < target.nodes.Length; i++)
        {
            MeshNode node = target.nodes[i] as MeshNode;
            if (node == null)
            {
                Debug.LogError("Node could not be casted to MeshNode. Node was null or no MeshNode");
                return;
            }
            sb.Append(string.Format("f {0}/0 {1}/0 {2}/0\n", node.v1 + 1, node.v2 + 1, node.v3 + 1));
        }

        string obj = sb.ToString();

        using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path))
        {
            sw.Write(obj);
        }
    }