private static void Main()
        {
            // One-time initialization per application
            DotsRuntime.Initialize();

            // Setup the global static string interning storage
            TempMemoryScope.EnterScope();
            WordStorage.Initialize();
            TempMemoryScope.ExitScope();

            // A UnityInstance can exist per game state (there may potentially be more than one)
            var unity = UnityInstance.Initialize();

            unity.OnTick = (double timestampInSeconds) =>
            {
                var shouldContinue = unity.Update(timestampInSeconds);
                if (shouldContinue == false)
                {
                    unity.Deinitialize();
                }
                return(shouldContinue);
            };

            // Anything which can come after EnterMainLoop must occur in an event because
            // on some platforms EnterMainLoop exits immediately and the application enters
            // an event-driven lifecycle.
            PlatformEvents.OnQuit          += (object sender, QuitEvent evt) => { Shutdown(); };
            PlatformEvents.OnSuspendResume += (object sender, SuspendResumeEvent evt) => { unity.Suspended = evt.Suspend; };

            // Run
            RunLoop.EnterMainLoop(unity.OnTick);

            // DON'T CALL ANY CLEANUP HERE!
        }
示例#2
0
    public static int Main(string[] args)
    {
        // Not using UnityInstance.Initialize here because it also creates a world, and some tests exist
        // that expect to handle their own world life cycle which currently conflicts with our world design
        UnityInstance.BurstInit();

        DotsRuntime.Initialize();

        TempMemoryScope.EnterScope();
        // Static storage used for the whole lifetime of the process. Create it once here
        // so heap tracking tests won't fight over the storage causing alloc/free mismatches
        WordStorage.Initialize();

        // TypeManager initialization uses temp memory, so let's free it before creating a global scope
        Unity.Entities.TypeManager.Initialize();
        TempMemoryScope.ExitScope();

        // Should have stack trace with tests
        NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;

        int result = 0;

#if UNITY_PORTABLE_TEST_RUNNER
        double start = Time.timeAsDouble;
        UnitTestRunner.Run();
        double end = Time.timeAsDouble;
        PrintResults(end - start);
#else
        result = new AutoRun().Execute(args);
#endif

        TempMemoryScope.EnterScope();
        Unity.Entities.TypeManager.Shutdown();
        WordStorage.Shutdown();
        TempMemoryScope.ExitScope();

        DotsRuntime.Shutdown();

        return(result);
    }