android下调试unity3d应用

 目前貌似不支持断点调试,但可以通过日志打印(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;

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 = "";    }   }  } }


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值