Example #1
0
        void SaveFile()
        {
            if (File.Exists(Application.dataPath + "/" + FileName + ".asset"))
            {
                File.Delete(Application.dataPath + "/" + FileName + ".asset");
            }

            AStarNodeFile t = ScriptableObject.CreateInstance <AStarNodeFile>();

            for (int i = 0; i < AStarNodeEditorScriptList.Count; ++i)
            {
                AStarNode n = AStarNodeEditorScriptList[i].node;
                TempGrid[n.RowIndex, n.ColumnIndex] = n;
            }

            for (int i = 0; i < Row; ++i)
            {
                for (int j = 0; j < Cloumn; ++j)
                {
                    t.AStarNodeList.Add(TempGrid[i, j]);
                }
            }
            AssetDatabase.CreateAsset(t, "Assets/" + FileName + ".asset");
            AssetDatabase.Refresh();
        }
Example #2
0
        void OnGUI()
        {
            GUILayout.BeginVertical();
            Row      = EditorGUILayout.IntField("行", Row);
            Cloumn   = EditorGUILayout.IntField("列", Cloumn);
            GridSize = EditorGUILayout.FloatField("格子大小", GridSize);

            GUILayout.BeginHorizontal();

            GUILayout.Label("导航格文件:");
            file = (AStarNodeFile)EditorGUILayout.ObjectField(file, typeof(AStarNodeFile));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("格子生成中心位置:");
            MapTransform = (Transform)EditorGUILayout.ObjectField(MapTransform, typeof(Transform));
            GUILayout.EndHorizontal();


            if (GUILayout.Button("生成导航格"))
            {
                ObstacleArray = GameObject.FindGameObjectsWithTag("Obstacle");
                CreateGrid();
            }

            if (file != null)
            {
                if (GUILayout.Button("读取导航格文件"))
                {
                    ObstacleArray = null;
                    CreateGrid();;
                }
            }

            if (TempGrid != null && TempGrid.Length > 0)
            {
                FileName = EditorGUILayout.TextField("文件名", FileName);
                if (GUILayout.Button("存储地图文件"))
                {
                    SaveFile();
                }

                if (GUILayout.Button("清空全部导航格"))
                {
                    TempGrid = null;
                }
            }
        }