目前貌似不支持斷點調試,但可以通過日志打印(logcat)來跟蹤。
在Android SDK中有個adb工具,使用此工具來跟蹤運行的android應用:
- adb logcat
啟動logcat,並將設備上運行的android應用的運行時信息全部打印出來。
- adb logcat -s Unity
如果只想打印Unity的輸出信息,使用此命令。
- adb logcat -d > logcat.txt
將打印信息輸出為文件。
當然,更直接的做法是在應用中集成自己的調試信息窗口,將如下代碼關聯到一個gameobject:
- using UnityEngine;
- using System.Collections;</p><p>public class GuiTextDebug : MonoBehaviour
- {
- private float windowPosition = -440.0f;
- private int positionCheck = 2;
- private static string windowText = "";
- private Vector2 scrollViewVector = Vector2.zero;
- private GUIStyle debugBoxStyle;
-
- private float leftSide = 0.0f;
- private float debugWidth = 420.0f;
-
- public bool debugIsOn = false;
-
- public static void debug(string newString)
- {
- windowText = newString + "\n" + windowText;
- UnityEngine.Debug.Log(newString);
- }
-
- void Start()
- {
- debugBoxStyle = new GUIStyle();
- debugBoxStyle.alignment = TextAnchor.UpperLeft;
- leftSide = 120;
- }
-
-
- void OnGUI()
- {
- if (debugIsOn)
- {
- GUI.depth = 0;
- GUI.BeginGroup(new Rect(windowPosition, 40.0f, leftSide, 200.0f));
-
- scrollViewVector = GUI.BeginScrollView(new Rect (0, 0.0f, debugWidth, 200.0f),
- scrollViewVector,
- new Rect (0.0f, 0.0f, 400.0f, 2000.0f));
- GUI.Box(new Rect(0, 0.0f, debugWidth - 20.0f, 2000.0f), windowText, debugBoxStyle);
- GUI.EndScrollView();
-
- GUI.EndGroup ();
-
- if (GUI.Button(new Rect(leftSide, 0.0f,75.0f,40.0f), "調試"))
- {
- if (positionCheck == 1)
- {
- windowPosition = -440.0f;
- positionCheck = 2;
- }
- else
- {
- windowPosition = leftSide;
- positionCheck = 1;
- }
- }
-
- if (GUI.Button(new Rect(leftSide + 80f,0.0f,75.0f,40.0f),"清除"))
- {
- windowText = "";
- }
- }
- }
- }