Skip to content

Instantly share code, notes, and snippets.

@flarb
Created May 23, 2015 18:50
Show Gist options
  • Save flarb/32a34c1e75f165f1b25c to your computer and use it in GitHub Desktop.
Save flarb/32a34c1e75f165f1b25c to your computer and use it in GitHub Desktop.

Revisions

  1. flarb renamed this gist May 23, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. flarb created this gist May 23, 2015.
    92 changes: 92 additions & 0 deletions SDKSwap
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    using System.IO;

    public class SDKSwap : EditorWindow {

    static string _cardboardPath;
    static string _OVRPath;

    static string _manifestPath = "/Plugins/Android/AndroidManifest.xml";

    [MenuItem ("Window/Tools/SDK Switch")]
    static void Init() {
    SDKSwap window = (SDKSwap)EditorWindow.GetWindow(typeof(SDKSwap));
    window.Show();
    }

    void OnGUI() {
    GUILayout.Label("Manifest Paths", EditorStyles.boldLabel);

    GUILayout.Space(10f);

    GUILayout.Label("Cardboard Manifest", EditorStyles.label);
    GUILayout.TextField(_cardboardPath);

    if (GUILayout.Button("Set Cardboard Manifest")) {
    foreach (Object o in Selection.objects) {
    _cardboardPath = AssetDatabase.GetAssetPath(o);
    EditorPrefs.SetString("cardboardPath", _cardboardPath);
    break;
    }
    }

    GUILayout.Label("OVR Manifest", EditorStyles.label);
    GUILayout.TextField(_OVRPath);

    if (GUILayout.Button ("Set OVR Manifest")) {
    foreach (Object o in Selection.objects) {
    _OVRPath = AssetDatabase.GetAssetPath(o);
    EditorPrefs.SetString("OVRPath", _OVRPath);
    break;
    }
    }

    GUILayout.Space(10f);

    GUILayout.Label("Swap SDKs", EditorStyles.boldLabel);

    if (GUILayout.Button("OVR Mode")) {
    SwapOVR();
    }

    if (GUILayout.Button("Cardboard Mode")) {
    SwapCardboard();
    }
    }

    void OnEnable() {

    _cardboardPath = EditorPrefs.GetString("cardboardPath", null);
    _OVRPath = EditorPrefs.GetString("OVRPath", null);
    }

    //[MenuItem ("Window/Tools/Cardboard")]
    static void SwapCardboard() {
    string trimPath = _cardboardPath.Substring(6, _cardboardPath.Length - 6);
    string fullPath = Application.dataPath + trimPath;
    Debug.Log("FP: " + fullPath + " to " + GetManifestPath());
    FileUtil.ReplaceFile(fullPath, GetManifestPath());

    AssetDatabase.Refresh();
    }

    //[MenuItem("Window/Tools/OVR Mobile")]
    static void SwapOVR() {
    string trimPath = _OVRPath.Substring(6, _OVRPath.Length - 6);
    string fullPath = Application.dataPath + trimPath;
    Debug.Log("FP: " + fullPath + " to " + GetManifestPath());
    FileUtil.ReplaceFile(fullPath, GetManifestPath());

    AssetDatabase.Refresh();
    }

    static string GetManifestPath() {

    string path = Application.dataPath + _manifestPath;

    return(path);
    }

    }