public void PreventSleep() { if (SleepUtil.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_AWAYMODE_REQUIRED) == 0) //Away mode for Windows >= Vista { SleepUtil.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_SYSTEM_REQUIRED); //Windows < Vista, forget away mode } }
/// <summary> /// Parse command line arguments and start initial model /// import (if any). /// </summary> private void ParseCommandLineArgs() { string[] args = Environment.GetCommandLineArgs(); bool profile = false; bool quitAfterLoad = false; long delayLoadMilliseconds = 0; // default model to load at startup, unless // --load or --no-load is used var uri = new Uri(Path.Combine(Application.streamingAssetsPath, "piggleston.glb")); var importOptions = GameManager.Instance.ImportOptions; var importTask = RuntimeGltfImporter.GetImportTask(uri, importOptions); for (int i = 0; i < args.Length; ++i) { if (args[i] == "--delay-load") { // Delay initial model import at startup. // I added this option so that I could prevent // Unity player loading/initialization from affecting // my profiling results. delayLoadMilliseconds = Int64.Parse(args[i + 1]); } else if (args[i] == "--load") { // Specify a model to load at startup, // in place of the default Piglet model. uri = new Uri(args[i + 1]); importTask = RuntimeGltfImporter.GetImportTask(uri, importOptions); } else if (args[i] == "--no-load") { // Don't load a model at startup. importTask = null; } else if (args[i] == "--profile") { // Record and log profiling results while // importing the initial model. This option times // IEnumerator.MoveNext() calls and identifies // which import subtasks cause the longest // interruptions the main Unity thread. profile = true; } else if (args[i] == "--quit-after-load") { // Exit the viewer immediately after loading // the initial model. This option is usually // used in conjunction with --profile to // perform automated profiling from the command // line. quitAfterLoad = true; } } if (importTask == null) { return; } if (delayLoadMilliseconds > 0) { importTask.PushTask(SleepUtil.SleepEnum( delayLoadMilliseconds)); } if (profile) { importTask.OnCompleted += _ => importTask.LogProfilingData(); } if (quitAfterLoad) { importTask.OnCompleted += _ => Application.Quit(0); } GameManager.Instance.StartImport(importTask, uri); }