SAMPLE CODE
All code provided on this page is intended as a sample. You may use it as-is, or adapt or port it as required.
NON-UNITY PROJECTS
For non-Unity projects, no additional code is required in your project for Niah to work. However, integrating or adapting the provided Basic Companion Code:
- dramatically improves timestamp accuracy,
- adds support for auto filtering multiple processes (in other words, if multiple debug sessions are running simultaneously from the same VS instance, the debug output will be automatically separated into separate filters), and
- allows you to double click an output line and jump directly to the source file line that wrote it.
Basic Companion Code: C++ | Version: 1.01 | niah.cpp niah.h
Beyond the Basic Companion Code are some additional tracing macros to help you trace the filename and line number such that you simply need to call DBG_WRITE() / DBG_WRITEW() or DBG_WRITE_LINE() / DBG_WRITE_LINEW() to unlock the full feature set of Niah.
Additional Companion Code: C++ | Version 1.01 | NiahEx.h stdext_string.h
To unlock the additional Niah functionality in C# (non Unity), a single source file is provided. Dropping this into your project allows you to call Niah.Debug.WriteLine() in the same way as you’d call System.Diagnostics.Debug.WriteLine().
Companion Code: C# | Version 1.00 | niah.cs
UNITY PROJECTS
For Unity projects, additional code is required in order to send Unity debug output to Visual Studio.
When you open a Unity solution in Visual Studio, Niah will start listening for a connection from the Niah Unity code below. The VS output window – in the Niah Text Filter pane – will display the connection ID that Niah is listening on. One reason that the connection could fail is if the Niah code in your Unity project does not use the same connection ID as the server. Therefore, if your Unity output is not displaying in VS, please verify that the connection ID calculated in the Niah code below matches the connection ID displayed in the Niah Text Filter VS output pane. If it does not, you can hardcode it in your Unity project code (and please let me know).
This code is intended as a sample. You may use it as-is, or adapt is as required. This code requires .Net 4 – which means you need to be using Unity 2018.1 or later, and your project needs to build against .Net 4 rather than .Net 2. An explanation of how to switch your project to .Net 4 is at
https://blogs.unity3d.com/2018/03/28/updated-scripting-runtime-in-unity-2018-1-what-does-the-future-hold/
Version 1.00: NamedPipeClient.cs NiahConsoleLogListener.cs