public void ButtonPress() { if (! Init()) return; GameObject obj = EventSystem.current.currentSelectedGameObject; if (obj.name == "Title" && ! buttonCanvas.overlayShowing) { #if DEVELOPMENT_BUILD && ! UNITY_EDITOR buttonCanvas.ShowQuestionOverlay( "THIS IS A DEVELOPMENT BUILD OF THE GAME.\n\nThis version of the game is for testing and evaluation purposes only. Please do not distribute.", "Proceed to game", null, delegate(string pressedButton) { buttonCanvas.HideOverlay(); #endif DeviceInput.RequestCameraPermission(); buttonCanvas.ShowBattery(); gameState.LoadScene("MapScene"); #if DEVELOPMENT_BUILD && ! UNITY_EDITOR } ); #endif } }
static void Update() { if (CheckIfProjectSwitchNeeded()) { return; } if (EditorApplication.isPlaying) { if (!AssetDatabase.IsValidFolder("Assets/_DO NOT COMMIT RIGHT NOW - Unity is using the project")) { if (buildNotReady) { // do not allow running at an inconsistent state Debug.LogError("Cannot play because MAGIS project is in an inconsistent state. Please fix any issues that weren't resolved by Autorun.CleanUp() and reload the project."); EditorApplication.isPlaying = false; return; } buildNotReady = true; // upon running, hide unnecessary resources AssetDatabase.CreateFolder("Assets", "_DO NOT COMMIT RIGHT NOW - Unity is using the project"); AssetDatabase.Refresh(); // force editor to play at 1x scale or lower Type type = typeof(EditorWindow).Assembly.GetType("UnityEditor.GameView"); EditorWindow w = EditorWindow.GetWindow(type); var areaField = type.GetField("m_ZoomArea", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); var areaObj = areaField.GetValue(w); var scaleField = areaObj.GetType().GetField("m_Scale", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); Vector2 value = (Vector2)scaleField.GetValue(areaObj); if (value.x > 1.0f) { scaleField.SetValue(areaObj, new Vector2(1.0f, 1.0f)); } loadedLevel = null; if (GameObject.FindWithTag("ARMarker") != null && GameObject.FindWithTag("AREngine") == null) { // temporarily halt the loading of an AR editor level to load CommonScene loadedLevel = SceneManager.GetActiveScene().name; SceneManager.LoadScene("CommonScene"); DeviceInput.RequestCameraPermission(); Debug.Log("Starting ARScene"); } else if (GameObject.Find("GameState") == null) { // for other levels that come with arengine, always run from the beginning if (SceneManager.GetActiveScene().name == "ARScene" || SceneManager.GetActiveScene().name == "ARSubscene" || SceneManager.GetActiveScene().name == "CommonScene" || SceneManager.GetActiveScene().name == "TitleScene" || SceneManager.GetActiveScene().name == "MapScene" || SceneManager.GetActiveScene().name == "") { SceneManager.LoadScene("CommonScene"); Debug.Log("Starting MAGIS from the title screen"); } } } else if (buildNotReady && loadedLevel != null) { // actually load the current editor level, and also load ARScene automatically if needed SceneManager.LoadScene(loadedLevel); SceneManager.LoadScene("ARScene", LoadSceneMode.Additive); loadedLevel = null; } } else if (!EditorApplication.isPlaying && !EditorApplication.isCompiling && !EditorApplication.isUpdating) { // automatically switch target to iOS or Android if the current target is Windows, macOS, etc. // (doing it here intentionally because we don't want to do it during Autorun constructor) if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS && EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android) { buildNotReady = true; if ((int)System.Environment.OSVersion.Platform == 4 || (int)System.Environment.OSVersion.Platform == 6) { EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS); } else { EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); } return; } else { if (!EditorUserBuildSettings.GetBuildLocation(BuildTarget.iOS).EndsWith("ios_" + DeviceInput.GameName())) { EditorUserBuildSettings.development = true; } EditorUserBuildSettings.buildAppBundle = !EditorUserBuildSettings.development; EditorUserBuildSettings.SetBuildLocation(BuildTarget.iOS, "ios_" + DeviceInput.GameName()); if (EditorUserBuildSettings.buildAppBundle) { EditorUserBuildSettings.SetBuildLocation(BuildTarget.Android, "aab_" + DeviceInput.GameName() + ".aab"); } else { EditorUserBuildSettings.SetBuildLocation(BuildTarget.Android, "apk_" + DeviceInput.GameName() + ".apk"); } } // fix to remove empty .fbm folders that create spurious meta files // (doing it here intentionally because we don't want to do it during Autorun constructor) foreach (string asset in AssetDatabase.FindAssets(".fbm")) { string folder = AssetDatabase.GUIDToAssetPath(asset); if (AssetDatabase.IsValidFolder(folder)) { if (AssetDatabase.FindAssets("t:Object", new[] { folder }).Length == 0) { buildNotReady = true; Debug.Log("Deleting empty folder " + folder); AssetDatabase.DeleteAsset(folder); } } } // fix to remove extraneous _TerrainAutoUpgrade // (doing it here intentionally because we don't want to do it during Autorun constructor) if (AssetDatabase.IsValidFolder("Assets/_TerrainAutoUpgrade")) { buildNotReady = true; Debug.Log("Deleting migration folder _TerrainAutoUpgrade"); AssetDatabase.DeleteAsset("Assets/_TerrainAutoUpgrade"); } CleanUp(); } else { buildNotReady = true; } }