示例#1
0
    private void InitConsole(bool isHeadless, List <string> commandLineArgs)
    {
        if (IsHeadless)
        {
#if UNITY_STANDALONE_WIN
            string consoleTitle        = "SteelX" + " [" + System.Diagnostics.Process.GetCurrentProcess().Id + "]";
            var    consoleRestoreFocus = commandLineArgs.Contains("-consolerestorefocus");

            var consoleUI = new ConsoleTextWin(consoleTitle, consoleRestoreFocus);
#elif UNITY_STANDALONE_LINUX
            var consoleUI = new ConsoleTextLinux();
#else
            UnityEngine.Debug.Log("WARNING: starting without a console");
            var consoleUI = new ConsoleNullUI();
#endif
            Console.Init(consoleUI);
        }
        else    //in-game UI
        {
            var consoleUI = Instantiate(Resources.Load <ConsoleGUI>("Prefabs/ConsoleGUI"));
            DontDestroyOnLoad(consoleUI);
            Console.Init(consoleUI);
        }
    }
示例#2
0
    public void Awake()
    {
        GameDebug.Assert(game == null);
        DontDestroyOnLoad(gameObject);
        game = this;

        m_StopwatchFrequency = System.Diagnostics.Stopwatch.Frequency;
        m_Clock = new System.Diagnostics.Stopwatch();
        m_Clock.Start();

        var buildInfo = FindObjectOfType <BuildInfo>();

        if (buildInfo != null)
        {
            _buildId = buildInfo.buildId;
        }

        var commandLineArgs = new List <string>(System.Environment.GetCommandLineArgs());

#if UNITY_STANDALONE_LINUX
        m_isHeadless = true;
#else
        m_isHeadless = commandLineArgs.Contains("-batchmode");
#endif
        var consoleRestoreFocus = commandLineArgs.Contains("-consolerestorefocus");

        if (m_isHeadless)
        {
#if UNITY_STANDALONE_WIN
            string consoleTitle;

            var overrideTitle = ArgumentForOption(commandLineArgs, "-title");
            if (overrideTitle != null)
            {
                consoleTitle = overrideTitle;
            }
            else
            {
                consoleTitle = Application.productName + " Console";
            }

            consoleTitle += " [" + System.Diagnostics.Process.GetCurrentProcess().Id + "]";

            var consoleUI = new ConsoleTextWin(consoleTitle, consoleRestoreFocus);
#elif UNITY_STANDALONE_LINUX
            var consoleUI = new ConsoleTextLinux();
#else
            UnityEngine.Debug.Log("WARNING: starting without a console");
            var consoleUI = new ConsoleNullUI();
#endif
            Console.Init(consoleUI);
        }
        else
        {
            var consoleUI = Instantiate(Resources.Load <ConsoleGUI>("Prefabs/ConsoleGUI"));
            DontDestroyOnLoad(consoleUI);
            Console.Init(consoleUI);

            m_DebugOverlay = Instantiate(Resources.Load <DebugOverlay>("DebugOverlay"));
            DontDestroyOnLoad(m_DebugOverlay);
            m_DebugOverlay.Init();

            var hdpipe = RenderPipelineManager.currentPipeline as HDRenderPipeline;
            if (hdpipe != null)
            {
//                hdpipe.DebugLayer2DCallback = DebugOverlay.Render;
//                hdpipe.DebugLayer3DCallback = DebugOverlay.Render3D;
            }

            m_GameStatistics = new GameStatistics();
        }

        // If -logfile was passed, we try to put our own logs next to the engine's logfile
        var engineLogFileLocation = "./logs";
        var logfileArgIdx         = commandLineArgs.IndexOf("-logfile");
        if (logfileArgIdx >= 0 && commandLineArgs.Count >= logfileArgIdx)
        {
            engineLogFileLocation = System.IO.Path.GetDirectoryName(commandLineArgs[logfileArgIdx + 1]);
        }

        var logName = m_isHeadless ? "game_" + DateTime.UtcNow.ToString("yyyyMMdd_HHmmss_fff") : "game";
        GameDebug.Init(engineLogFileLocation, logName);

        ConfigVar.Init();

        Console.EnqueueCommandNoHistory("exec -s " + k_UserConfigFilename);

        // Default is to allow no frame cap, i.e. as fast as possible if vsync is disabled
        Application.targetFrameRate = -1;

        if (m_isHeadless)
        {
            Application.targetFrameRate = serverTickRate.IntValue;
            QualitySettings.vSyncCount  = 0; // Needed to make targetFramerate work; even in headless mode

#if !UNITY_STANDALONE_LINUX
            if (!commandLineArgs.Contains("-nographics"))
            {
                GameDebug.Log("WARNING: running -batchmod without -nographics");
            }
#endif
        }
        else
        {
            RenderSettings.Init();
        }

        // Out of the box game behaviour is driven by boot.cfg unless you ask it not to
        if (!commandLineArgs.Contains("-noboot"))
        {
            Console.EnqueueCommandNoHistory("exec -s " + k_BootConfigFilename);
        }

        var forceClientSystem = commandLineArgs.Contains("-forceclientsystems");
        if (!m_isHeadless || forceClientSystem)
        {
            m_SoundSystem = new SoundSystem();
            m_SoundSystem.Init(audioMixer);
            m_SoundSystem.MountBank(defaultBank);

            GameObject go = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/ClientFrontend", typeof(GameObject)));
            UnityEngine.Object.DontDestroyOnLoad(go);
            clientFrontend = go.GetComponentInChildren <ClientFrontend>();
        }

        sqpClient = new SQP.SQPClient();

        GameDebug.Log("FPS Sample initialized");
#if UNITY_EDITOR
        GameDebug.Log("Build type: editor");
#elif DEVELOPMENT_BUILD
        GameDebug.Log("Build type: development");
#else
        GameDebug.Log("Build type: release");
#endif
        GameDebug.Log("BuildID: " + buildId);
        GameDebug.Log("Cwd: " + System.IO.Directory.GetCurrentDirectory());

        SimpleBundleManager.Init();
        GameDebug.Log("SimpleBundleManager initialized");

        levelManager = new LevelManager();
        levelManager.Init();
        GameDebug.Log("LevelManager initialized");

        inputSystem = new InputSystem();
        GameDebug.Log("InputSystem initialized");
        inputSystem.SetVRInput();

        // TODO (petera) added Instantiate here to avoid making changes to asset file.
        // Feels like maybe SO is not really the right tool here.
        config = Instantiate((GameConfiguration)Resources.Load("GameConfiguration"));
        GameDebug.Log("Loaded game config");

        // Game loops
        Console.AddCommand("preview", CmdPreview, "Start preview mode");
        Console.AddCommand("serve", CmdServe, "Start server listening");
        Console.AddCommand("client", CmdClient, "client: Enter client mode. Looking for servers");
        Console.AddCommand("boot", CmdBoot, "Go back to boot loop");
        Console.AddCommand("connect", CmdConnect, "connect <ip>: Connect to server on ip (default: localhost)");

        Console.AddCommand("menu", CmdMenu, "show the main menu");
        Console.AddCommand("load", CmdLoad, "Load level");
        Console.AddCommand("quit", CmdQuit, "Quits");
        Console.AddCommand("screenshot", CmdScreenshot, "Capture screenshot. Optional argument is destination folder or filename.");
        Console.AddCommand("crashme", (string[] args) => { GameDebug.Assert(false); }, "Crashes the game next frame ");
        Console.AddCommand("saveconfig", CmdSaveConfig, "Save the user config variables");
        Console.AddCommand("loadconfig", CmdLoadConfig, "Load the user config variables");

#if UNITY_STANDALONE_WIN
        Console.AddCommand("windowpos", CmdWindowPosition, "Position of window. e.g. windowpos 100,100");
#endif

        Console.SetOpen(true);
        Console.ProcessCommandLineArguments(commandLineArgs.ToArray());

        PushCamera(bootCamera);
    }
示例#3
0
    /*
     * THIS CAUSES RANDOM CRASHES
     *
     * private static void PreLoadAnimationNodes()
     * {
     *          // In Editor, convince Burst to JIT compile all Animation UNode types immediately.
     #if UNITY_EDITOR
     *          var start = UnityEngine.Time.realtimeSinceStartup;
     *          var wasSyncCompile = Menu.GetChecked("Jobs/Burst/Synchronous Compilation");
     *          Menu.SetChecked("Jobs/Burst/Synchronous Compilation", true);
     *          try
     *          {
     *              var animAssembly = typeof(Unity.Animation.AnimationGraphSystem).Assembly;
     *              var unodeNonGenericTypes = animAssembly.GetTypes().Where(t =>
     *                  t.IsClass && !t.IsAbstract && !t.IsGenericType &&
     *                  typeof(Unity.DataFlowGraph.INodeFunctionality).IsAssignableFrom(t));
     *              var unodeGenericTypesReferencedInData = animAssembly.GetTypes()
     *                  .Where(t => !t.IsClass && typeof(Unity.DataFlowGraph.INodeData).IsAssignableFrom(t))
     *                  .Select(t => t
     *                      .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
     *                      .Select(fi => fi.FieldType)
     *                      .Where(ft => ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(Unity.DataFlowGraph.NodeHandle<>))
     *                      .Select(ft => ft.GetGenericArguments()[0])
     *                      .Where(ft => ft.IsGenericType))
     *                  .SelectMany(t => t)
     *                  .Distinct();
     *
     *              var nodeSet = new Unity.DataFlowGraph.NodeSet();
     *
     *              MethodInfo getFunctionality = nodeSet.GetType().GetMethod("GetFunctionality", new System.Type[0]);
     *              foreach (System.Type t in unodeNonGenericTypes.Concat(unodeGenericTypesReferencedInData))
     *                  getFunctionality.MakeGenericMethod(t).Invoke(nodeSet, null);
     *
     *              nodeSet.Dispose();
     *
     *              Debug.Log($"Compilation of Animation UNode types took {UnityEngine.Time.realtimeSinceStartup - start} seconds");
     *          }
     *          finally
     *          {
     *              Menu.SetChecked("Jobs/Burst/Synchronous Compilation", wasSyncCompile);
     *          }
     #endif
     * }
     */

    public void Awake()
    {
        GameDebug.Assert(game == null);
        DontDestroyOnLoad(gameObject);
        game = this;

        GameApp.IsInitialized = true;

        //PreLoadAnimationNodes();

        m_StopwatchFrequency = System.Diagnostics.Stopwatch.Frequency;
        m_Clock = new System.Diagnostics.Stopwatch();
        m_Clock.Start();

#if UNITY_EDITOR
        _buildUnityVersion = InternalEditorUtility.GetFullUnityVersion();
#endif
        var buildInfo = FindObjectOfType <BuildInfo>();
        if (buildInfo != null)
        {
            _buildId           = buildInfo.buildId;
            _buildUnityVersion = buildInfo.buildUnityVersion;
        }

        var commandLineArgs = new List <string>(System.Environment.GetCommandLineArgs());

        // TODO we should only initialize this if we have a graphics device (i.e. non-headless)
        Overlay.Managed.Initialize();

#if UNITY_STANDALONE_LINUX
        m_isHeadless = true;
#else
        m_isHeadless = commandLineArgs.Contains("-batchmode");
#endif
        var noconsole           = commandLineArgs.Contains("-noconsole");
        var consoleRestoreFocus = commandLineArgs.Contains("-consolerestorefocus");
        if (noconsole)
        {
            UnityEngine.Debug.Log("WARNING: starting without a console");
            var consoleUI = new ConsoleNullUI();
            Console.Init(buildId, buildUnityVersion, consoleUI);
        }
        else if (m_isHeadless)
        {
#if UNITY_EDITOR
            Debug.LogError("ERROR: Headless mode not supported in editor");
#endif

#if UNITY_STANDALONE_WIN
            string consoleTitle;

            var overrideTitle = ArgumentForOption(commandLineArgs, "-title");
            if (overrideTitle != null)
            {
                consoleTitle = overrideTitle;
            }
            else
            {
                consoleTitle = Application.productName + " Console";
            }

            consoleTitle += " [" + System.Diagnostics.Process.GetCurrentProcess().Id + "]";

            var consoleUI = new ConsoleTextWin(consoleTitle, consoleRestoreFocus);
#elif UNITY_STANDALONE_LINUX
            var consoleUI = new ConsoleTextLinux();
#else
            UnityEngine.Debug.Log("WARNING: starting without a console");
            var consoleUI = new ConsoleNullUI();
#endif
            Console.Init(buildId, buildUnityVersion, consoleUI);
        }
        else
        {
            var consoleUI = Instantiate(Resources.Load <ConsoleGUI>("Prefabs/ConsoleGUI"));
            DontDestroyOnLoad(consoleUI);
            Console.Init(buildId, buildUnityVersion, consoleUI);

            m_DebugOverlay = Instantiate(Resources.Load <DebugOverlay>("DebugOverlay"));
            DontDestroyOnLoad(m_DebugOverlay);
            m_DebugOverlay.Init();

            m_GameStatistics = new GameStatistics();
        }

        // If -logfile was passed, we try to put our own logs next to the engine's logfile
        // if -logfile was set to "-" we forward our logs to Debug.Log, so that it ends up on stdout.
        var engineLogFileLocation = ".";
        var logName             = m_isHeadless ? "game_" + DateTime.UtcNow.ToString("yyyyMMdd_HHmmss_fff") : "game";
        var logfileArgIdx       = commandLineArgs.IndexOf("-logfile");
        var forceForwardToDebug = false;
        if (logfileArgIdx >= 0 && commandLineArgs.Count >= logfileArgIdx)
        {
            var logFile = commandLineArgs[logfileArgIdx + 1];
            if (logFile == "-")
            {
                forceForwardToDebug = true;
            }
            else
            {
                engineLogFileLocation = System.IO.Path.GetDirectoryName(logFile);
            }
        }
        GameDebug.Init(engineLogFileLocation, logName, forceForwardToDebug);

        ConfigVar.Init();

        // Support -port and -query_port as per Multiplay standard
        var serverPort = ArgumentForOption(commandLineArgs, "-port");
        if (serverPort != null)
        {
            Console.EnqueueCommandNoHistory("server.port " + serverPort);
        }

        var sqpPort = ArgumentForOption(commandLineArgs, "-query_port");
        if (sqpPort != null)
        {
            Console.EnqueueCommandNoHistory("server.sqp_port " + sqpPort);
        }

        Console.EnqueueCommandNoHistory("exec -s " + k_UserConfigFilename);

        // Default is to allow no frame cap, i.e. as fast as possible if vsync is disabled
        Application.targetFrameRate = -1;

        if (m_isHeadless)
        {
            Application.targetFrameRate = serverTickRate.IntValue;
            QualitySettings.vSyncCount  = 0; // Needed to make targetFramerate work; even in headless mode

#if !UNITY_STANDALONE_LINUX
            if (!commandLineArgs.Contains("-nographics"))
            {
                GameDebug.Log("WARNING: running -batchmod without -nographics");
            }
#endif
        }
        else
        {
            RenderSettings.Init();
        }

        // Out of the box game behaviour is driven by boot.cfg unless you ask it not to
        if (!commandLineArgs.Contains("-noboot"))
        {
            Console.EnqueueCommandNoHistory("exec -s " + k_BootConfigFilename);
        }

        if (m_isHeadless)
        {
            SoundSystem.Initialize(new SoundSystemNull());
        }
        else
        {
            var soundSystem = new SoundSystemBase();
            soundSystem.Init(audioMixer);
            SoundSystem.Initialize(soundSystem);

            GameObject go = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/ClientFrontend", typeof(GameObject)));
            UnityEngine.Object.DontDestroyOnLoad(go);
            clientFrontend = go.GetComponentInChildren <ClientFrontend>();
        }

        sqpClient = new SQP.SQPClient();

        GameDebug.Log("A2 initialized");
#if UNITY_EDITOR
        GameDebug.Log("Build type: editor");
#elif DEVELOPMENT_BUILD
        GameDebug.Log("Build type: development");
#else
        GameDebug.Log("Build type: release");
#endif
        GameDebug.Log("BuildID: " + buildId);
        GameDebug.Log("Unity: " + buildUnityVersion);
        GameDebug.Log("Cwd: " + System.IO.Directory.GetCurrentDirectory());

        levelManager = new LevelManager();
        levelManager.Init();
        GameDebug.Log("LevelManager initialized");

        GameDebug.Log("InputSystem initialized");

        // Game loops
        Console.AddCommand("serve", CmdServe, "Start server listening");
        Console.AddCommand("client", CmdClient, "client: Enter client mode.");
        Console.AddCommand("thinclient", CmdThinClient, "client: Enter thin client mode.");
        Console.AddCommand("boot", CmdBoot, "Go back to boot loop");
        Console.AddCommand("connect", CmdConnect, "connect <ip>: Connect to server on ip (default: localhost)");

        Console.AddCommand("menu", CmdMenu, "show the main menu");
        Console.AddCommand("load", CmdLoad, "Load level");
        Console.AddCommand("quit", CmdQuit, "Quits");
        Console.AddCommand("screenshot", CmdScreenshot, "Capture screenshot. Optional argument is destination folder or filename.");
        Console.AddCommand("crashme", (string[] args) => { GameDebug.Assert(false); }, "Crashes the game next frame ");
        Console.AddCommand("saveconfig", CmdSaveConfig, "Save the user config variables");
        Console.AddCommand("loadconfig", CmdLoadConfig, "Load the user config variables");

        Console.AddCommand("profile", CmdProfile, "Run the profiling for a level");

#if UNITY_STANDALONE_WIN
        Console.AddCommand("windowpos", CmdWindowPosition, "Position of window. e.g. windowpos 100,100");
#endif

        Console.SetOpen(true);
        Console.ProcessCommandLineArguments(commandLineArgs.ToArray());
#if UNITY_IOS
        // (marton) This is a hack to work around command line arguments not working on iOS
        if (!Application.isEditor)
        {
            Console.EnqueueCommandNoHistory("preview Level_00");
        }
#endif



        GameApp.CameraStack.OnCameraEnabledChanged += OnCameraEnabledChanged;
        GameApp.CameraStack.PushCamera(bootCamera);
    }