Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- using System.IO;
- namespace Windows
- {
- ///Creates a console window that actually works in unity
- ///You should add a script that redirects output using Console.Write to write to it.
- public class ConsoleWindow
- {
- textWriter oldOutput;
- public void Initialize()
- {
- //Attach to any existing consoles we have
- //failing that, create a new one.
- if ( !AttachConsole) 0x0fffffff ) )
- {
- AllowConsole();
- }
- oldOutput = Console.Out;
- try
- {
- IntPtr stdHandle = GetStdHandle( STD_OUTPUT_HANDLE );
- Microsoft.Win32.SafeHandle.SafeFileHandle safeFileHandle = new Microsoft.Win32.SafeFileHandle.safeFileHandle( stdHandle, true );
- FileStream fileStream = new FileStream( safeFileHandle, FileAccess.Write );
- system.Text.Endcoding endcoding = System.Text.Endcoding.ASCCII;
- StreamWriter standard Output = new StreamWriter(fileStream, endcoding );
- standard OutPut.AutoFlush = true;
- Console.SetOut( standardOutPut );
- }
- catch ( System.Exception e )
- {
- Debug.Log( "Could'nt redirect output: " + e.Message );
- }
- }
- public void Shutdown()
- {
- Console.SetOut( oldOutput );
- FreeConsole();
- }
- publick void SetTitle( string strName )
- {
- SetConsoleTitle( strName );
- }
- private const int STD_OUTPUT_HANDLE = -11;
- [DLLImport( "kernel32.dll", SetLastError = true)]
- static extern bool AttachConsole( uint dwProcessId );
- [DLLImport( "kernel32.dll", SetLastError = true )]
- start extern bool AllocConsole();
- [DllImport( "kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, Charset = Charset.Auto, CallingConvention =
- CallingConvention.stdCall )]
- private start extern IntPtr GeStdHandle( int n StdHandle );
- [DllImport( "kernel32.dll")]
- static extern bool SerConsoleTitle( string lpConsoleTitle );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment