static void InitAfterEditorStartup()
        {
            EditorApplication.update -= InitAfterEditorStartup;

            if (!ValidateInstallerIntegrity())
            {
                EditorUtility.DisplayDialog("Installer incomplete", "Not all files required for Sample Installation exist. Most likely, they have been installed already. If you find any issues with the Sample Files, just Install the Sample Scripts again through the Package Manager or contact the Package Developer.", "OK");
                DeleteAssetAtGuid(sampleDefinitionsInstallerGuid);
                return;
            }

            UpdateGameDefinitionPaths();

            if (!HasGameDefinitions || MakeBackupOfGameDefinitions())
            {
                var sampleDefinitionPath = AssetDatabase.GUIDToAssetPath(sampleGameDefinitionsDirectoryGuid);
                var path = GameDefinitionSettings.Load().gameDefinitionDirectoryPath;
                PathUtility.DeleteDirectoryIfExists(path);
                Directory.Move(sampleDefinitionPath, path);
                CleanUpMetaFiles(path);
                File.Delete(Path.ChangeExtension(sampleDefinitionPath, "meta"));
                GameDefinitionHub.OpenWindow();
            }

            GUID.TryParse(startSceneGuid, out var parsedStartSceneGUID);
            if (EditorBuildSettings.scenes.All(scene => scene.guid != parsedStartSceneGUID) && EditorUtility.DisplayDialog("Change Build Scenes", $"In order for the Simulation Mode to work for these samples, we need to add a new Start-Scene to your Build Settings. Can we proceed?", "OK", "Cancel"))
            {
                EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(parsedStartSceneGUID, true) }.Concat(EditorBuildSettings.scenes).ToArray();
            }

            DeleteAssetAtGuid(sampleDefinitionsInstallerGuid);
            AssetDatabase.Refresh();
        }
 public GameDefinitionBuild(string[] directories, bool clearDirectory, BuildTarget[] buildTargets, System.Type gameDefinitionType, GameDefinitionSettings gameDefinitionSettings, GameDefinitionBuildSettings buildSettings)
 {
     this.directories        = directories;
     this.clearDirectory     = clearDirectory;
     this.buildTargets       = buildTargets;
     this.gameDefinitionType = gameDefinitionType;
     this.settings           = gameDefinitionSettings;
     this.buildSettings      = buildSettings;
 }
        void Awake()
        {
            var settings = GameDefinitionSettings.Load();

            EnsureSingletonInstance();
            if (!Application.isEditor)
            {
                SetNativeApi(CreateNativeAPI());
            }
        }
        static TGameDefinition LoadGameDefinition(string path, GameDefinitionSettings settings)
        {
            var jsonPath = Path.Combine(path, settings.gameDefinitionFileName);

            if (!File.Exists(jsonPath))
            {
                throw new Exception($"No {settings.gameDefinitionFileName} found at contentBundleFolderPath {path}.");
            }

            var jsonString = File.ReadAllText(jsonPath);
            var definition = JsonUtility.FromJson <TGameDefinition>(jsonString);

            return(definition);
        }
        static bool MakeBackupOfGameDefinitions()
        {
            var path       = GameDefinitionSettings.Load().gameDefinitionDirectoryPath;
            var dateString = DateTime.Now.ToString("yyyyMMdd-hhmmss");
            var backupPath = $"{Path.GetDirectoryName(path)}-{dateString}";

            if (!EditorUtility.DisplayDialog("GameDefinitions already Exist.", $"The sample scripts need to install into your GameDefinitions-Path in order to be executable. Your existing GameDefinitions will be moved to {backupPath} if you confirm. If you cancel, you can find the GameDefinitions in the Sample-Directory and move them manually.", "OK", "Cancel"))
            {
                return(false);
            }

            Directory.Move(path, backupPath);
            return(true);
        }
        IMediaboxServer IMediaboxServerFactory.Create()
        {
            if (GameDefinitionSettings.Load().ServerMode != ServerMode.Simulation)
            {
                Debug.Log($"{nameof(GameDefinitionSettings)}.{nameof(GameDefinitionSettings.ServerMode)} is not {nameof(ServerMode)}.{nameof(ServerMode.Simulation)}. Returning null.");
                return(null);
            }

            Debug.Log($"Creating new{nameof(StreamingAssetsMediaboxServer)}");

            if (this.simulationRunner == null)
            {
                this.simulationRunner = new SimulationModeRunner(new UnityPlayerPrefs(), () => true, () => this.mediaboxServer);
            }

            this.mediaboxServer = new StreamingAssetsMediaboxServer(bundleName, new GUIDialog());
            return(this.mediaboxServer);
        }
        public async void SetContentBundleFolder(string path)
        {
            try {
                await ResetGame();

                var definition = default(TGameDefinition);
                var settings   = GameDefinitionSettings.Load();
                path = FixWronglyZippedArchive(path);
                if (settings.useGameDefinitionJsonFile)
                {
                    definition = LoadGameDefinition(path, settings);
                    if (definition is IGameBundleDefinition gameBundleDefinition)
                    {
                        await LoadGameDefinitionBundle(path, gameBundleDefinition);

                        if (definition is IGameSceneDefinition gameSceneDefinition)
                        {
                            if (definition is IGameBundleSceneDefinition gameBundleSceneDefinition)
                            {
                                await this.loadedBundle.LoadScene(gameBundleSceneDefinition.SceneName);
                            }
                            else
                            {
                                await LoadGameDefinitionScene(gameSceneDefinition);
                            }
                        }
                        else
                        {
                            //await LoadAllScenesInBundle(this.loadedBundle);
                        }
                    }
                }
                await OnStartGame(path, definition, this.saveGamePath);
                await FindGame().Load(this.saveGamePath);
                await FindGame().SetLanguage(this.language);
                await FindGame().StartGame(path, definition);

                this.mediaboxServer.OnLoadingSucceeded();
            } catch (Exception e) {
                Debug.LogException(e);
                this.mediaboxServer.OnLoadingFailed();
            }
        }
 public EditorMediaboxServer(string bundleName, GameDefinitionSettings settings) : base(bundleName, new EditorGUIDialog())
 {
     this.settings = settings;
 }
 public EditorBuildMediaboxServer(string bundleName, GameDefinitionSettings settings, GameDefinitionBuildSettings buildSettings) : base(bundleName, settings)
 {
     this.buildSettings = buildSettings;
     PathUtility.EnsureEmptyDirectory(this.buildSettings.tempSimulationBuildPath);
 }
 public ArchiveGameDefinitionBuildStep(GameDefinitionSettings settings, GameDefinitionBuildSettings buildSettings, bool clearDirectory)
 {
     this.settings       = settings;
     this.buildSettings  = buildSettings;
     this.clearDirectory = clearDirectory;
 }