游戏: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";
        }
    }
}


前端网页加载渲染链路优化

opensignal官方提供了2018年2月份统计的全世界4G网络覆盖率和通信速率的统计分布图如下,在目前移动互联网的浪潮下,我们要利用好用户终端设备的每个字节的流量。

Unity进阶技巧 - RectTransform详解

前言 最近要做UI,有时候需要在代码中调整改变UI控件的属性,比如位置、大小等,然而在NGUI里面,控制UI控件的位置等属性的是RectTransform这个组件,这个组件继承自Transform组件,却增加许多自己的特性,在不了解这些特性的情况下鲁莽的去使用它,会导致出现很多匪夷所思的问题,而且使用起来也不够得心应手,于是决定研究一下RectTransform到底是如何工作的 你将学得到什...

unity圆圈自动吸附屏幕边缘

效果: 设置如下:

Unity UGUI优化:解决EventSystem耗时过长的问题 第三部分

则跳过这个anvas:public override void aycast(ointerventata eventata, ist<aycastesult> resultppendist) { if (canvas ==