分类 Unity 下的文章

Unity 中獲取 TextMesh Pro, 點 Unity.Editor.asmdef 進行編輯
50197-bp33m2y6sou.png

搜索 TextMsh Pro 加入, 滑到下方點 Apply 套用
70570-jdz869wm4yd.png

切換到 Editor 腳本

using TMPro;

//get
transform.Find("Text_ID").GetComponent<TextMeshPro>().text = "123";

今天打包版本測試轟炸超人發現這個問題

StackOverflowException: The requested operation caused a stack overflow. at (wrapper managed-to-native) System.String.FastAllocateString(int) at System.String.CreateStringFromEncoding (System.Byte* bytes, System.Int32 byteLength, System.Text.Encoding encoding) [0x00013] in <c9d3ffd4b98649ee9989e1908eaca019>:0 at System.Text.Encoding.GetString (System.Byte* bytes, System.Int32 byteCount) [0x00033] in <c9d3ffd4b98649ee9989e1908eaca019>:0 at System.Text.Encoding.GetString (System.ReadOnlySpan1[T] bytes) [0x00013] in :0
at System.String.Ctor (System.SByte value, System.Int32 startIndex, System.Int32 length, System.Text.Encoding enc) [0x0006d] in :0
at System.String.CreateString (System.SByte
value, System.Int32 startIndex, System.Int32 length, System.Text.Encoding enc) [0x00000] in :0
at (wrapper managed-to-managed) System.String..ctor(sbyte,int,int,System.Text.Encoding)
at UnityEngine.StackTraceUtility.ExtractStackTrace () [0x0002c] in :0
at (wrapper managed-to-native) UnityEngine.DebugLogHandler.Internal_Log(UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
at UnityEngine.DebugLogHandler.LogFormat (UnityEngine.LogType logType, UnityEngine.Object context, System.String format, System.Object[] args) [0x0000b] in :0
at UnityEngine.Logger.Log (UnityEngine.LogType logType, System.Object message) [0x00027] in :0
at UnityEngine.Debug.Log (System.Object message) [0x00006] in :0
at ETModel.Log.Debug (System.String msg) [0x00000] in G:\OlgCase\bbm\source\Unity_Web\Assets\Model\Base\Log.cs:14
at ILRuntime.Runtime.Generated.ETModel_Log_Binding.Debug_8 (ILRuntime.Runtime.Intepreter.ILIntepreter __intp, ILRuntime.Runtime.Stack.StackObject
esp, System.Collections.Generic.List`1[T] mStack, ILRuntime.CLR.Method.CLRMethod method, System.Boolean isNewObj) [0x0003a] in G:\OlgCase\bbm\source\Unity_Web\Assets\Model\ILBinding\ETModel_Log_Binding.cs:222
at (wrapper delegate-invoke) .invoke_StackObject_ILIntepreter_StackObject_List1<object>_CLRMethod_bool(ILRuntime.Runtime.Intepreter.ILIntepreter,ILRuntime.Runtime.Stack.StackObject*,System.Collections.Generic.List1,ILRuntime.CLR.Method.CLRMethod,bool)
at ILRuntime.Runtime.Intepreter.ILIntepreter.Execute (ILRuntime.CLR.Method.ILMethod method, ILRuntime.Runtime.Stack.StackObject esp, System.Boolean& unhandledException) [0x0387d] in G:\OlgCase\bbm\source\Unity_Web\Assets\ThirdParty\ILRuntime\ILRuntime\Runtime\Intepreter\ILIntepreter.cs:2219
at ILRuntime.Runtime.Intepreter.ILIntepreter.Execute (ILRuntime.CLR.Method.ILMethod method, ILRuntime.Runtime.Stack.StackObject
esp, System.Boolean& unhandledException) [0x03711] in G:\OlgCase\bbm\source\Unity_Web\Assets\ThirdParty\ILRuntime\ILRuntime\Runtime\Intepreter\ILIntepreter.cs:2173
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.<>c:b0_0(Object, UnhandledExceptionEventArgs)e
`

很明顯是出現了無限循環, 但不確定問題在哪, 測試了發現是 AIPlayer 造成的, 並且問題在尋路上

不知道為什麼這邊的計算公式如果設定 depth > 200 , 就會造成 depth = 39 就卡死

private void reCalcNonPath(int[,] matrixData, ref List<int[]> path, int bombCnt, int depth, int chunkH, int chunkW)
{
    if (path.Count <= 0){
        return;
    }
    int[] last = path[path.Count - 1];
    //
    if (depth > 30){
        return;
    }

改掉了就好了

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

最近在做新手引導系統, 遇到了些問題, 先說說新手引導的設計吧

一、新手引導UI

預設作法如下, 去看了下以前的做法似乎有些問題需要解決, 以前用 NGUI 做這塊, 需要將目標 UI 顯示層級提上來, 當時我的作法是把目標 Button parent 換成教學 UI Panel, 這樣就能保證要點擊目標一定會在最上層
33163-uzqhom9nj2.png

現在項目使用 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 就已經決定誰高誰低了
94201-1cfhiru1usk.png

Order in Layer

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

在 Sprite Renderer 可以設定這兩個值
43936-9hz0ff5lsvg.png

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

mSpine_Teacher.GetComponent<MeshRenderer>().sortingLayerID = SortingLayer.NameToID("Spine");
mSpine_Teacher.GetComponent<MeshRenderer>().sortingOrder = 1;

最後呈現出來的效果是這樣
27106-b8ado9haxra.png

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

首先開啟 AssetStudioGUI
56533-xssdnwijam8.png

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

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

切換到資源列表, 並點類型排序
96427-dr0n1ygrhel.png

可以直接查看包體內容
42052-yy9rtnr5hs.png