在使用 Canvas 將物件層級提高後出現一個問題, 被提高層級的物件跟底下的 Button Click 全都失效了, 查了 google 說是在添加 Canvas 同時必須增加 Graphic Raycaster, 如下, 這樣就能解決問題了
JK secret
搜尋此網誌
2024年5月16日 星期四
新手引導UI設計
最近在做新手引導系統, 遇到了些問題, 先說說新手引導的設計吧
一、新手引導UI
預設作法如下, 去看了下以前的做法似乎有些問題需要解決, 以前用 NGUI 做這塊, 需要將目標 UI 顯示層級提上來, 當時我的作法是把目標 Button parent 換成教學 UI Panel, 這樣就能保證要點擊目標一定會在最上層
現在項目使用 UGUI, UGUI 顯示層級是看 UI 順序的, 不然就是修改 Sorting Layer 或 Order in Layer
[Sorting Layer]
Sorting Layer 可以想像是一個大類, 在這個列表下渲染是按照這個清單順序的, 譬如
A物件
Sorting layer: UI
Order in Layer: 10
B物件
Sorting layer: Fx
Order in Layer: 1
就算你設定比較高的 Order in Layer, A物件也不可能比B物件層級高, 這是因為在 Sorting Layer 就已經決定誰高誰低了
Order in Layer
在同一個 Sorting Layer 下你可以藉由 Order in Layer 決定先後, 值越大層級越高
在 Sprite Renderer 可以設定這兩個值
mSpine_Teacher.GetComponent<MeshRenderer>().sortingLayerID = SortingLayer.NameToID("Spine"); mSpine_Teacher.GetComponent<MeshRenderer>().sortingOrder = 1;
2024年5月15日 星期三
'Activator.CreateInstance(type)' threw an exception of type 'System.MissingMethodException'
服務端跑起來發現出現了很多警告, 警告內容是註冊消息 OpCode = 0, 警告如下
消息opcode为0: C2S_BomberGame_QueryFrameMessage
順著流程查看
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false); if (attrs.Length == 0){ continue; } MessageAttribute messageAttribute = attrs[0] as MessageAttribute; if (messageAttribute == null){ continue;
this.typeMessages.Add(messageAttribute.Opcode, Activator.CreateInstance(type));
發現 Activator.CreateInstance(type) 執行到 MarketInfo 就掛了, 出現這個錯誤
'Activator.CreateInstance(type)' threw an exception of type 'System.MissingMethodException' object {System.MissingMethodException}
後來查看 MarketInfo.cs 發現了 constructor 沒有寫, 補上去就好了, 就這段
2024年5月12日 星期日
Chloe Procedure 使用
在開發好友系統時, 做了個功能叫做推薦名單, 也就是將最近對戰的玩家記錄到數據表上, 再推給客戶端, 但在獲取數據時發現必須過濾掉已經添加的清單, 索性在表格上添加了一個字段來紀錄是否有效
後來發現Chloe處理這段很麻煩, 沒查到官方有 replace 的功能, 所以自己用了 procedure 來處理, 有點久沒用研究了下 Chole 怎麼調用
DbParam iUserId = new DbParam("@iUserId", userId); DbParam iRUserId = new DbParam("@iRUserId", recentUserId); DbParam iState = new DbParam("@iState", 1); dbContext.SqlQuery<Tbl_Recent>("proc_update_recent", CommandType.StoredProcedure, iUserId, iRUserId, iState);
2024年5月10日 星期五
AssetStudioGUI 使用
AssetStudioGUI 可以用來查看 Unity 包體內容, 可以多看看其他優質產品的資源內容怎麼做的
首先開啟 AssetStudioGUI
2024年5月1日 星期三
IL_00af: call System.Int32& System.Int32[0...,0...]::Address
打包app執行轟炸超人發現遊戲開局就crash了....
在pc上複查發現這個錯誤最後發現是這邊出錯, int[,]在查詢數據時 address 不知道為什麼出錯了
詳細錯誤如下
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再使用就好了
2024年4月29日 星期一
ILRuntime 性能優化
在使用 ILRuntime需要注意
1) 減少使用 foreach, Dictionary, IEnumerable 的調用會產生額外 GC
2) 減少調用主工程包含enum參數的函數, 因為在調用的時候會進行值得轉型, 產生額外 GC
3) ILBinding需要執行, 否則runtime性能會差很多