Automate production settings for Oculus Go store (Unity)

If you’re developing VR apps for the Oculus Go with Unity and want to distribute them through the Oculus Go store, you need to set up your app for production in Unity. However, Unity offers no easy way to go between development and production settings, making the process a pain in the ass and error prone.

Here’s a small script I wrote that automates most of those tasks. Specifically, it:

Hopefully this helps you :-)

using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;


// Sets the Build Mode
public class BuildMode {

  static string currentMode;

  [MenuItem("Kosmos/Dev Mode")]
  static void setDevMode() {
    setMode("dev");
  }

  [MenuItem("Kosmos/Prod Mode")]
  static void setProdMode() {
    setMode("prod");
  }

  static void setMode(string mode) {
    if (mode == "dev" && currentMode != "dev") {
      // set dev mode
      PlayerSettings.applicationIdentifier = "com.yourcompany.YourApp_dev";
      PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.Mono2x);
      OVRManifestPreprocessor.RemoveAndroidManifest();
      setKeystore(false);
      setEntitlementCheck(false);
      currentMode = "dev";
      return;
    }

    if (mode == "prod" && currentMode != "prod") {
      // set prod mode
      PlayerSettings.applicationIdentifier = "com.yourcompany.YourApp";
      PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
      PlayerSettings.bundleVersion = (float.Parse(PlayerSettings.bundleVersion) + 0.01f).ToString("#.00");
      PlayerSettings.Android.bundleVersionCode = PlayerSettings.Android.bundleVersionCode + 1;
      OVRManifestPreprocessor.GenerateManifestForSubmission();
      setKeystore(true);
      setEntitlementCheck(true);
      currentMode = "prod";
      return;
    }
  }

  static void setKeystore(bool isEnabled) {
    if (isEnabled) {
      PlayerSettings.Android.keystoreName = EnvKeys.KEYSTORE_NAME; // full local path
      PlayerSettings.Android.keyaliasName = EnvKeys.KEYALIAS_NAME;
      PlayerSettings.Android.keyaliasPass = EnvKeys.KEYALIAS_PASS;
      PlayerSettings.Android.keystorePass = EnvKeys.KEYSTORE_PASS;
      return;
    }
    PlayerSettings.Android.keystoreName = "";
    PlayerSettings.Android.keyaliasName = "";
    PlayerSettings.Android.keyaliasPass = "";
    PlayerSettings.Android.keystorePass = "";
  }

  // you might need to adapt this depending how you handle the entitlement check
  static void setEntitlementCheck(bool isEnabled) {
      EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
      EditorSceneManager.OpenScene("Assets/Shared/Scenes/WelcomeScreen.unity");
      GameObject gameController = GameObject.Find("GameController");
      gameController.GetComponent<OculusPlatformSetup>().DoEntitlementCheck = isEnabled;
      EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
  }
}