真Unity3d_Astarpath的应用

导出数据

https://www.lanindex.com/unity2d%E6%B8%B8%E6%88%8F%E9%A1%B9%E7%9B%AE%E5%AF%BC%E5%87%BA%E5%9C%B0%E5%9B%BE%E6%95%B0%E6%8D%AE/

 

C# 生成图片 按照像素值或画图

处理 1/3 的图片 || 整张处理

真Unity3d_Astarpath的应用_第1张图片

原链接,用的Bitmap,我是不知道一般的Unity团队都怎么会用这个的,但是百度能百度到很多

https://blog.csdn.net/shenshendeai/article/details/53780109

我改了一下方法,用Texture2D实现,而且改成无需 [运行时] 实现

static void GenCurrntMapData() {
        //if (Application.isPlaying == false)
        //{
        //    BuildManager.MessageBox(IntPtr.Zero, "需要先运行场景,另外A*需要使用Grid Graph", "地图Data", 0);
        //    return;
        //}
        //GraphCaches 是 AStarPath Pro 的输出目录
        string tmpPath = Application.dataPath + "/GraphCaches/" + SceneManager.GetActiveScene().name;
        //目录不存在容错
        string tmpDir = System.IO.Path.GetDirectoryName(tmpPath);
        if (Directory.Exists(tmpDir) ==false)
        {
            Directory.CreateDirectory(tmpDir);
        }
        var astar = GameObject.FindObjectOfType();
        //原来的必须运行时的代码
        //AstarData data = astar.data;
        //AstarData data = AstarPath.active.data;
        //GridGraph grid = data.gridGraph;
        //Editor 无需运行,但是AStar 输出的是GridGraph
        GridGraph grid = (GridGraph)astar.graphs[0];
        
        //文件第一行:录入文件说明 x列有多少格子,y行有多少格子,每个格子的长x,每个格子的高y
        string formatFull = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}",
            grid.width,grid.depth,
            grid.nodeSize,grid.aspectRatio,
            grid.center.x, grid.center.y,grid.center.z);
        //StreamWriter 初始化尽量放后,要不前面grid 出错,而StreamWriter已经初始化并开始读取文件
        //StreamWriter 放前面会出错而没有处理到,导致死锁文件(tmpPath)
        StreamWriter tmpStreamWriter = new StreamWriter(tmpPath);
        tmpStreamWriter.WriteLine(formatFull);
        //-------------------------------------------------------------------
        //实际游戏开发过程中并不能简单的以0、1作为能不能走的判断
        //因为肯定可能有多层,所以用0表示不能走,1~9表示能走的层
        //-------------------------------------------------------------------
        //文件后续行:录入节点信息
        string linecontent = "";
        for (int i = 0; i < grid.CountNodes(); i++)
        {
            //GridNode node = grid.nodes[i];
            int x_index = i % grid.width;
            int y_index = i / grid.width;
            GridNode node = grid.nodes[ (y_index + 1) * grid.width - 1 - x_index];
            //测试 node.area 是否固定(不定)
            //string str = string.Format("{0}({1}) ", (node.Walkable ? "1" : "0"), node.Area);
            string str = string.Format("{0}", (node.Area==33 ? "1" : "0"));
            //string str = string.Format("{0}", (node.Area >0 ? node.Area.ToString() : "0"));
            if ((i + 1) % grid.width == 0)
            {
                linecontent += str;
                tmpStreamWriter.WriteLine(linecontent);
                linecontent = "";
            }
            else
            {
                linecontent += str;
            }
        }

        tmpStreamWriter.WriteLine();
        tmpStreamWriter.Flush();
        tmpStreamWriter.Close();

        GenSnapshotPng(grid.width, grid.depth, grid.nodes);
        //BuildManager.MessageBox(IntPtr.Zero, "生成" + SceneManager.GetActiveScene().name + " + Snapshot.png 完成", "地图Data", 0);
    }

 

CharacterController SimpleMove 和 Move 的区别

在游戏开发的几年过程中,好像真的很少用过Charactercontroller,也没怎么深入研究过,因为一般都是封装好;但是想深入也不容易,因为也都是封装好的;所以,只能通过一些例子,窥探SimpleMove 和 Move的不同

https://blog.csdn.net/alexander_xfl/article/details/41419723/

你可能感兴趣的:(每天一点u3d)