Exemplo n.º 1
0
    public void GoToRandomPosition()
    {
        Vector3 tempPosition = NavMeshUtil.GetRandomLocation();

        GoToPosition(tempPosition);
    }
 protected override void OnGUI()
 {
     base.OnGUI();
     GUI.enabled = !Application.isPlaying;
     GUILayout.BeginHorizontal();
     EditorGUI.BeginChangeCheck();
     editMode = GUILayout.Toggle(editMode, "Edit", EditorStyles.toolbarButton);
     if (EditorGUI.EndChangeCheck())
     {
         OnEditModeUpdate();
     }
     if (GUILayout.Button("Revert", EditorStyles.toolbarButton))
     {
         navMeshTri.triangulation = NavMeshTriangulationObject.Empty;
         editMode = false;
         OnEditModeUpdate();
     }
     GUILayout.EndHorizontal();
     GUI.enabled = true;
     GUILayout.BeginHorizontal();
     GUI.color = Color.yellow;
     if (GUILayout.Button("Export", EditorStyles.toolbarButton))
     {
         string path = EditorUtility.SaveFilePanel("选择保存路径", "", "NetMesh.data", "data");
         try
         {
             BinaryWriter         writer   = new BinaryWriter(new FileStream(path, FileMode.Create), System.Text.Encoding.UTF8);
             NavMeshTriangulation t        = NavMesh.CalculateTriangulation();
             List <Vector3>       vertices = null;
             List <int>           indices  = null;
             List <int>           layers   = null;
             NavMeshUtil.FilterDuplicate(t, out vertices, out indices, out layers);
             Debug.Log("顶点数量: " + vertices.Count);
             writer.Write(vertices.Count);
             vertices.ToList <Vector3>().ForEach((Vector3 each) =>
             {
                 writer.Write(each.x);
                 writer.Write(each.y);
                 writer.Write(each.z);
             });
             writer.Write(layers.Count);
             Debug.Log("三角形数量: " + layers.Count);
             indices.ToList <int>().ForEach((int each) =>
             {
                 writer.Write(each);
             });
             layers.ToList <int>().ForEach((int each) =>
             {
                 writer.Write(each);
             });
             writer.Flush();
             writer.Close();
         }
         catch (Exception e)
         {
             Debug.LogError(e.Message + "\n" + e.StackTrace);
         }
     }
     GUI.color = Color.white;
     GUILayout.EndHorizontal();
 }