游戏:unity保存log堆栈到本地


public class Test : MonoBehaviour
{

    //文件的路径
    public string path;
    StreamWriter writer;
    StreamReader reader;

    void Start()
    {
        SetPath();

        // 方法一
        FileInfo file = new FileInfo(path);
        if (file.Exists)
        {
            // file.Delete();
            //  file.Refresh();
        }

        // 方法二
        if (File.Exists(path))
        {
            File.Delete(path);
        }
    }


    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Debug.Log("Log");
            Debug.LogError("LogError");
            Debug.LogWarning("LogError");
        }
    }


    void OnEnable()
    {
        Application.logMessageReceivedThreaded += OnLogMessageReceivedThreaded;
        System.AppDomain.CurrentDomain.UnhandledException += _OnUnresolvedExceptionHandler;
    }

    void OnDisable()
    {
        Application.logMessageReceivedThreaded -= OnLogMessageReceivedThreaded;
        System.AppDomain.CurrentDomain.UnhandledException -= _OnUnresolvedExceptionHandler;

    }

    private void OnLogMessageReceivedThreaded(string condition, string stackTrace, LogType type)
    {
        StringBuilder str = new StringBuilder();
        str.Append(type.ToString() + ":" + condition + "    堆栈信息:" + stackTrace);
        //   WriteIntoTxt(str.ToString());
        WriteIntoTxtTown(str.ToString());
    }

    private void _OnUnresolvedExceptionHandler(object sender, UnhandledExceptionEventArgs e)
    {
        Debug.LogError(sender);
    }

    // 方法一
    public void WriteIntoTxt(string message)
    {
        FileInfo file = new FileInfo(path);
        if (!file.Exists)
        {
            writer = file.CreateText();
        }
        else
        {
            writer = file.AppendText();
        }
        writer.WriteLine(message);
        writer.Flush();
        writer.Dispose();
        writer.Close();
    }

    // 方法二
    public void WriteIntoTxtTown(string message)
    {
        File.AppendAllText(path, message);
    }



    void SetPath()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            path = Application.persistentDataPath + "/logInfo.txt";
        }
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = Application.streamingAssetsPath + "/logInfo.txt";
        }
    }
}


打假!看看哪些是工作中的形式主义、官僚主义

更多精彩,为您推荐说吧!中央给基层的这些减负大招,你赞不赞?警醒!这些落马干部,都在这个根本性的大问题上犯糊涂问题干部必看!你的,唉……惩贪除恶,是为了让老百姓心情好!中央首次脱贫攻坚专项巡视,挖出了啥问题

亚马逊SEO优化,快速提升产品排名!

SEO就是指搜索引擎优化,大家常说的提升产品排名,其实就是最终优化的结果。因为亚马逊不仅是一个电商平台,它也和百度、谷歌等其他搜索引擎一样。

电商团队要怎么建,岗位怎么分,工资怎么开,来这里都可以告诉你

想开一个运营团队卖货,不清楚前期需要投入多少钱;传统线下工厂想转战电商不懂基础投入及团队人员如何配置。

分析香港的网站服务器对建站有影响吗?对SEO有什么影响吗?

为此企鹅博客查询了不少资料,总结了这篇文章,小伙伴们可以看看哦!其实在回答这个问题前,我们要先知道,网站收录一定要百度蜘蛛抓取的页面才有可能被收录。

做有活力的网站?超实用网页动画指南值得收藏 | 分享

现如今,动画对于网页设计师已经不再新奇,它正在成为最基础的交互设计效果。动画就是变化,是一种运动。下面就来跟范儿姐一起来了解一下网页动画吧~01网页动画简史正所谓,了解一件事物,就