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


Unity 导出 iOS 游戏并上架 App Store

logread/1878Unity 导出 iOS 游戏并上架 App Store 0. 前言 因为之前已经上架过一款 App(Swift 语言),所以开发者账号、证书这些都已经搞定了,如果你是第一次上架 iOS 应用,具体流程可以参考本文末尾列出的教程。这

unity圆圈自动吸附屏幕边缘

效果: 设置如下:

Android开发:简述Android布局优化的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blo…g.csdn.net/qq_/article/details/ ndroid开…发:简述ndroid布局优化的方法作为android应用来讲,无论应用本身多么美观,

Unity和Cocos2D在2D游戏开发上的对比

游戏开发的最好技术是什么:nity还是ocos?在网上你可以找到很多这两种技术的对比…。在我们开发游戏之前,我们要了解相关数据和信息并决定使用那种技术。但是人们对这两种技…术的对比大多都比较主观。擅长ocos的人会偏向于ocos。而使用nity的人则偏向于

关于“如何学习游戏开发不知道从哪方面入手”的相关建议

前言:作为一名上海上市游戏公司的关卡和战斗策划,简单来聊一下我对学习游戏制作的方法吧…。一、明确我的工作内容游戏的制作由三个领域的专业人士共同完成。我们通常见到的游戏,比…如有哪些功能,什么样的画面好不好看,玩法是有哪些怎么玩,主要是由三个部分组成:游戏策