add canvas cause button click not work
在使用 Canvas 將物件層級提高後出現一個問題, 被提高層級的物件跟底下的 Button Click 全都失效了, 查了 google 說是在添加 Canvas 同時必須增加 Graphic Raycaster, 如下, 這樣就能解決問題了

urscos Tech.
在使用 Canvas 將物件層級提高後出現一個問題, 被提高層級的物件跟底下的 Button Click 全都失效了, 查了 google 說是在添加 Canvas 同時必須增加 Graphic Raycaster, 如下, 這樣就能解決問題了

最近在做新手引導系統, 遇到了些問題, 先說說新手引導的設計吧
一、新手引導UI
預設作法如下, 去看了下以前的做法似乎有些問題需要解決, 以前用 NGUI 做這塊, 需要將目標 UI 顯示層級提上來, 當時我的作法是把目標 Button parent 換成教學 UI Panel, 這樣就能保證要點擊目標一定會在最上層

現在項目使用 UGUI, UGUI 顯示層級是看 UI 順序的, 不然就是修改 Sorting Layer 或 Order in Layer
Sorting Layer
Sorting Layer 可以想像是一個大類, 在這個列表下渲染是按照這個清單順序的, 譬如
A物件
B物件
就算你設定比較高的 Order in Layer, A物件也不可能比B物件層級高, 這是因為在 Sorting Layer 就已經決定誰高誰低了

Order in Layer
在同一個 Sorting Layer 下你可以藉由 Order in Layer 決定先後, 值越大層級越高

在 Sprite Renderer 可以設定這兩個值

Spine 用的 Mesh Renderer 雖然沒有, 但其實都是繼承 render, 可以直接調用修改

mSpine_Teacher.GetComponent<MeshRenderer>().sortingLayerID = SortingLayer.NameToID("Spine");
mSpine_Teacher.GetComponent<MeshRenderer>().sortingOrder = 1;
最後呈現出來的效果是這樣

AssetStudioGUI 可以用來查看 Unity 包體內容, 可以多看看其他優質產品的資源內容怎麼做的
首先開啟 AssetStudioGUI

將 unity 的包給解壓, 用來測試的是之前上傳 Google Play 的 RummyGo aab包

AssetStudioGUI 點擊 文件->加載目錄, 選擇解壓目錄

切換到資源列表, 並點類型排序

可以直接查看包體內容

打包app執行轟炸超人發現遊戲開局就crash了....


在pc上複查發現這個錯誤

最後發現是這邊出錯, int[,]在查詢數據時 address 不知道為什麼出錯了
for (int j = 0; j < map.MapConfig.ChunkH; j++){
strm += "[";
for (int i = 0; i < map.MapConfig.ChunkW; i++){
//這邊出錯
strm += matrixData[j, i] + ",";
}
strm += "],";
}
strm += "]";
詳細錯誤如下
IL_00af: call System.Int32& System.Int32[0...,0...]::Address(System.Int32,System.Int32)
at ETHotfix.AIPlayer.calcNonPath(System.Int32 depth) (at G:/OlgCase/bbm/source/Unity/Assets/Hotfix/GameGather/Bomber/AI/AIPlayer.cs:366)
at ETHotfix.AIPlayer.calcPath() (at G:/OlgCase/bbm/source/Unity/Assets/Hotfix/GameGather/Bomber/AI/AIPlayer.cs:200)
at ETHotfix.AIPlayer.V_Think() (at G:/OlgCase/bbm/source/Unity/Assets/Hotfix/GameGather/Bomber/AI/AIPlayer.cs:86)
at ETHotfix.AIPlayer.think() (at G:/OlgCase/bbm/source/Unity/Assets/Hotfix/GameGather/Bomber/AI/AIPlayer.cs:79)
at ETHotfix.AILogic.UpdateLogic() (at G:/OlgCase/bbm/source/Unity/Assets/Hotfix/GameGather/Bomber/AI/AILogic.cs:292)
at ETHotfix.BaseEntity.updateAILogicAct() (at G:/OlgCase/bbm/source/Unity/Assets/Hotfix/GameGather/Bomber/Entity/BaseEntity.cs:1581)
代碼修改, 把查詢給int再使用就好了
for (int j = 0; j < map.MapConfig.ChunkH; j++){
strm += "[";
for (int i = 0; i < map.MapConfig.ChunkW; i++){
num = matrixData[j, i];
strm += num + ",";
}
strm += "],";
以後有空再來查這個問題
在使用 ILRuntime需要注意
升級 ILRuntime 到 2.x 版本在 1.6 版本打包Android(package Hotfix.dll by Release)跟 Editor 下的性能非常糟糕,所有的消耗都在 GC 上面,後來升級 2.x 版本就好了
從更新後重新生成 ILBinding 發現修改了 IList 改成 using AutoList,這部分應該是優化了GC回收效率