Beispiel #1
0
    void DoAutosave(System.Action <string> onComplete)
    {
        using (Util.Profile("autosave"))
        {
            var sw = new System.Diagnostics.Stopwatch();
            sw.Restart();

            string destId = GetSlotBundleId(nextSlot);
            nextSlot = (nextSlot + 1) % maxSlots;

            // SaveMaybeOverwrite doesn't delete all files. Like thumbnails, if any.
            using (Util.Profile("deleteSlotBundle"))
            {
                if (bundleLibrary.BundleExists(destId))
                {
                    bundleLibrary.DeletePermanently(destId);
                }
            }

            GameBundle.Metadata meta = new GameBundle.Metadata
            {
                name        = $"{System.DateTime.Now} Autosave",
                description = $""
            };

            // Copy from the active bundle so our autosave looks like it.
            string srcId = GameBuilderApplication.ActiveBundleId;
            using (Util.Profile("CopyBundle"))
            {
                if (srcId != null && bundleLibrary.BundleExists(srcId))
                {
                    var srcBundle = bundleLibrary.GetBundle(srcId);
                    meta       = srcBundle.GetMetadata();
                    meta.name += $" ({System.DateTime.Now} Autosave)";

                    bundleLibrary.CopyBundle(srcId, destId);
                }
            }

            using (Util.Profile("SaveBundle"))
            {
                // Now overwrite just the scene.voos file
                bundleLibrary.SaveMaybeOverwrite(saveLoad, destId, meta, null, () =>
                {
                    sw.Stop();
                    Util.Log($"autosave took total of {sw.ElapsedMilliseconds}ms");
                    // TODO copy the steam workshop meta data too, if it's there.

                    lastAutosaveId   = destId;
                    lastAutosaveTime = Time.unscaledTime;
                    onComplete?.Invoke(destId);
                });
            }
        }
    }
    void GameResuming.ResumeOptionHandler.HandleBundleId(string bundleId)
    {
        if (!library.BundleExists(bundleId))
        {
            return;
        }
        var entry = library.GetBundleEntry(bundleId);

        // tutorialButton.gameObject.SetActive(false);
        resumeButton.gameObject.SetActive(true);
        resumeButton.SetThumbnail(entry.bundle.GetThumbnail());
        resumeButton.SetName(entry.bundle.GetMetadata().name);
        resumeButton.OnClick = () =>
        {
            popups.AskHowToPlay(playOpts =>
            {
                loadingScreen.ShowAndDo(() =>
                {
                    scenes.RestartAndLoadLibraryBundle(entry, playOpts);
                });
            });
        };
    }