Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using UnityEngine;
- using System.Linq;
- using System.Runtime.InteropServices;
- namespace Game
- {
- public class ApplicationManager : MonoBehaviour
- {
- #if UNITY_STANDALONE_WIN
- [DllImport("Kernel32.dll")]
- private static extern bool AllocConsole();
- #endif
- private const int Fps = 60;
- private const int HeadlessFps = 60;
- private static bool? _headless;
- public static bool Headless
- {
- get
- {
- if (!_headless.HasValue)
- _headless = Environment.GetCommandLineArgs().Contains("-batchmode");
- return _headless.Value;
- }
- }
- private void Awake()
- {
- DontDestroyOnLoad(gameObject);
- #if UNITY_STANDALONE_WIN
- Application.targetFrameRate = Headless ? HeadlessFps : Fps;
- if (Headless)
- {
- // set up console
- {
- AllocConsole();
- Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = true});
- //Console.SetIn(new StreamReader(Console.OpenStandardInput())); // doesn't work
- Application.logMessageReceivedThreaded +=
- (condition, stackTrace, type) => Console.WriteLine(condition + " " + stackTrace);
- }
- AudioListener.volume = 0f;
- }
- #endif
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement