歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android下調試Unity3D應用

Android下調試Unity3D應用

日期:2017/3/1 10:52:17   编辑:Linux編程
目前貌似不支持斷點調試,但可以通過日志打印(logcat)來跟蹤。

在Android SDK中有個adb工具,使用此工具來跟蹤運行的android應用:

  1. adb logcat

啟動logcat,並將設備上運行的android應用的運行時信息全部打印出來。

  1. adb logcat -s Unity

如果只想打印Unity的輸出信息,使用此命令。

  1. adb logcat -d > logcat.txt

將打印信息輸出為文件。

當然,更直接的做法是在應用中集成自己的調試信息窗口,將如下代碼關聯到一個gameobject:

  1. using UnityEngine;
  2. using System.Collections;</p><p>public class GuiTextDebug : MonoBehaviour
  3. {
  4. private float windowPosition = -440.0f;
  5. private int positionCheck = 2;
  6. private static string windowText = "";
  7. private Vector2 scrollViewVector = Vector2.zero;
  8. private GUIStyle debugBoxStyle;
  9. private float leftSide = 0.0f;
  10. private float debugWidth = 420.0f;
  11. public bool debugIsOn = false;
  12. public static void debug(string newString)
  13. {
  14. windowText = newString + "\n" + windowText;
  15. UnityEngine.Debug.Log(newString);
  16. }
  17. void Start()
  18. {
  19. debugBoxStyle = new GUIStyle();
  20. debugBoxStyle.alignment = TextAnchor.UpperLeft;
  21. leftSide = 120;
  22. }
  23. void OnGUI()
  24. {
  25. if (debugIsOn)
  26. {
  27. GUI.depth = 0;
  28. GUI.BeginGroup(new Rect(windowPosition, 40.0f, leftSide, 200.0f));
  29. scrollViewVector = GUI.BeginScrollView(new Rect (0, 0.0f, debugWidth, 200.0f),
  30. scrollViewVector,
  31. new Rect (0.0f, 0.0f, 400.0f, 2000.0f));
  32. GUI.Box(new Rect(0, 0.0f, debugWidth - 20.0f, 2000.0f), windowText, debugBoxStyle);
  33. GUI.EndScrollView();
  34. GUI.EndGroup ();
  35. if (GUI.Button(new Rect(leftSide, 0.0f,75.0f,40.0f), "調試"))
  36. {
  37. if (positionCheck == 1)
  38. {
  39. windowPosition = -440.0f;
  40. positionCheck = 2;
  41. }
  42. else
  43. {
  44. windowPosition = leftSide;
  45. positionCheck = 1;
  46. }
  47. }
  48. if (GUI.Button(new Rect(leftSide + 80f,0.0f,75.0f,40.0f),"清除"))
  49. {
  50. windowText = "";
  51. }
  52. }
  53. }
  54. }
Copyright © Linux教程網 All Rights Reserved