把unity console中的log信息读取到自己写的panel上

2 篇文章 0 订阅

unity打包安卓后,唯一的办法就是用Eclipse 中的DDSM 抓取apklog信息来测试APK包的问题,

但是本人对安卓那套abd.exe各种搞不定,说白了,Eclipse连接手机真的要看运气

所以,自己写一个Panel+ScrollView+ text 


实现也简单,没有过多的整理,直接扔上来,记录一二,好记性不如烂笔头啊

public class DebugPanel : MonoBehaviour
{

    public static DebugPanel Instance;

    public Text logText;
    public RectTransform content;

    private int count = 0;
    private Vector2 contentVe2 = new Vector2();
    StringBuilder MyStrBulder;
    private bool isUpdate = false;

    private bool isShow = false;

    private DebugPanel()
    {
        if (Instance == null)
            Instance = this;
    }

    private string strDebg = string.Empty;

    public void AddText(string str)
    {
        isUpdate = true;
        MyStrBulder.AppendFormat("{0}:{1}\n", count, str);
        count++;
        isUpdate = false;

    }
    // Use this for initialization
    void Awake()
    {
        MyStrBulder = new StringBuilder();

#if UNITY_5
            Application.logMessageReceived += HandleLog;  
#else
        Application.logMessageReceived += HandleLog;
#endif

    }

    void HandleLog(string message, string stackTrace, LogType type)
    {
        switch (type)
        {
            case LogType.Error:
                message = "<color=#FF0000>" + message+"</color>";
                break;
            case LogType.Assert:
                message = "<color=#0000ff>" + message + "</color>";
                break;
            case LogType.Warning:
                message = "<color=#EEEE00>" + message + "</color>";
                break;
            case LogType.Log:
                message = "<color=#000000>" + message + "</color>";
                break;
            case LogType.Exception:
                break;
            default:
                break;
        }

        AddText(message);
    }

    public void ShowHide()
    {
        isShow = !isShow;
        if (isShow)
        {
            transform.GetChild(0).localPosition = new Vector3(-9990, 0, 0);
        }
        else
        {
            transform.GetChild(0).localPosition = new Vector3(0, 0, 0);
        }
    }

    private bool isAdd = false;
    // Update is called once per frame
    void Update()
    {
        logText.text = MyStrBulder.ToString();
        //logText.text += MyStrBulder;
        contentVe2.Set(200, 23.5f * count);
        content.sizeDelta = contentVe2;
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值