Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace Game
  8. {
  9.     public class ApplicationManager : MonoBehaviour
  10.     {
  11. #if UNITY_STANDALONE_WIN
  12.         [DllImport("Kernel32.dll")]
  13.         private static extern bool AllocConsole();
  14. #endif
  15.  
  16.         private const int Fps = 60;
  17.         private const int HeadlessFps = 60;
  18.  
  19.         private static bool? _headless;
  20.  
  21.         public static bool Headless
  22.         {
  23.             get
  24.             {
  25.                 if (!_headless.HasValue)
  26.                     _headless = Environment.GetCommandLineArgs().Contains("-batchmode");
  27.  
  28.                 return _headless.Value;
  29.             }
  30.         }
  31.  
  32.         private void Awake()
  33.         {
  34.             DontDestroyOnLoad(gameObject);
  35.  
  36. #if UNITY_STANDALONE_WIN
  37.             Application.targetFrameRate = Headless ? HeadlessFps : Fps;
  38.  
  39.             if (Headless)
  40.             {
  41.                 // set up console
  42.                 {
  43.                     AllocConsole();
  44.                     Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = true});
  45.                     //Console.SetIn(new StreamReader(Console.OpenStandardInput())); // doesn't work
  46.                     Application.logMessageReceivedThreaded +=
  47.                         (condition, stackTrace, type) => Console.WriteLine(condition + " " + stackTrace);
  48.                 }
  49.  
  50.                 AudioListener.volume = 0f;
  51.             }
  52. #endif
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement