示例#1
0
    bool JumpToSource(LogStackFrame frame)
    {
        if (frame.FileName != null)
        {
            var osFileName = XLogger.ConvertDirectorySeparatorsFromUnityToOS(frame.FileName);
            var filename   = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), osFileName);
            if (System.IO.File.Exists(filename))
            {
                if (UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(filename, frame.LineNumber))
                {
                    return(true);
                }
            }
        }

        return(false);
    }
示例#2
0
    string GetSourceForFrame(LogStackFrame frame)
    {
        if (SourceLinesFrame == frame)
        {
            return(SourceLines);
        }

        if (frame.FileName == null)
        {
            return("");
        }

        var osFileName = XLogger.ConvertDirectorySeparatorsFromUnityToOS(frame.FileName);
        var filename   = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), osFileName);

        if (!System.IO.File.Exists(filename))
        {
            return("");
        }

        int lineNumber  = frame.LineNumber - 1;
        int linesAround = 3;
        var lines       = System.IO.File.ReadAllLines(filename);
        var firstLine   = Mathf.Max(lineNumber - linesAround, 0);
        var lastLine    = Mathf.Min(lineNumber + linesAround + 1, lines.Length);

        SourceLines = "";
        if (firstLine != 0)
        {
            SourceLines += "...\n";
        }
        for (int i = firstLine; i < lastLine; i++)
        {
            string str = lines[i] + "\n";
            SourceLines += str;
        }
        if (lastLine != lines.Length)
        {
            SourceLines += "...\n";
        }

        SourceLinesFrame = frame;
        return(SourceLines);
    }