Last active
May 14, 2023 13:41
-
-
Save forcepusher/7663ebfde8805c4a478a4907abbc7cd5 to your computer and use it in GitHub Desktop.
Unity "void Main" OOP template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using System.Threading.Tasks; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
namespace BananaParty.FurryGame.Client | |
{ | |
/// <summary> | |
/// Entry point for wiring up the engine and executing main loop. | |
/// </summary> | |
public static class Program | |
{ | |
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] | |
public static async void Main() | |
{ | |
// Prevent Unity Test Framework from shitting itself. | |
#if UNITY_EDITOR | |
if (SceneManager.GetActiveScene().name.StartsWith("InitTestScene")) | |
return; | |
#elif UNITY_INCLUDE_TESTS | |
return; | |
#endif | |
// Start editor playmode from scene 0. | |
#if UNITY_EDITOR | |
AsyncOperation sceneLoadingOperation = SceneManager.LoadSceneAsync(0); | |
while (!sceneLoadingOperation.isDone) | |
await Task.Yield(); | |
#endif | |
// Output Trace events, but don't duplicate them in a web export. | |
#if UNITY_EDITOR || !UNITY_WEBGL | |
Trace.Listeners.Add(new UnityConsoleTraceListener | |
{ | |
Filter = new EventTypeFilter(SourceLevels.Information) | |
}); | |
#endif | |
bool quitting = false; | |
Application.quitting += () => { quitting = true; }; | |
Stopwatch stopwatch = new(); | |
stopwatch.Start(); | |
using (var clientApplication = new ClientApplication( | |
new UnityRenderLibrary(), | |
new UnitySceneFactory(), | |
new UnityUserInterfaceLibrary())) | |
{ | |
while (!quitting) | |
{ | |
clientApplication.ExecuteFrame(stopwatch.ElapsedMilliseconds); | |
await Task.Yield(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scenes are no longer the root of your project, nor the game code depends on Unity Engine.
Ripped directly out of personal project without modifications.