導出資料
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 的圖檔 || 整張處理
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICM38FdsYkRGZkRG9lcvx2bjxiNx8VZ6l2cs0TRU1EerRVYyYkMMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnLyIjNzQTNyETM0AzNwkTMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
原連結,用的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<AstarPath>();
//原來的必須運作時的代碼
//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/