/// <summary>
    /// Exports and uploads the saber via adb
    /// </summary>
    /// <param name="bloq"></param>
    void ExportAndUpload(BloqReferences bloq)
    {
        string bloqName = bloq.descriptor.objectName + "." + extension;
        string path     = EditorUtility.SaveFilePanel("Save " + extension + " file", "", bloqName, extension);

        if (path == "")
        {
            EditorUtility.DisplayDialog("Exportation Failed!", "Invalid path", "OK");
            return;
        }

        string folderPath = Path.GetDirectoryName(path) + "/";

        if (exporterConfig.ipAddress != "")
        {
            QosmeticUtils.adb("connect " + exporterConfig.ipAddress + ":5555");
        }

        QosmeticUtils.adb("shell am force-stop com.beatgames.beatsaber");

        ExportBloqFile(bloq, folderPath);

        QosmeticUtils.adb("push \"" + folderPath + bloqName + "\" \"" + questPath + bloqName + "\"");
        QosmeticUtils.adb("shell am start com.beatgames.beatsaber/com.unity3d.player.UnityPlayerActivity");

        EditorUtility.DisplayDialog("Exportation Successful!", "If the game did not turn off or the bloq is not showing up, make sure your quest is connected through adb", "OK");
        EditorUtility.RevealInFinder(folderPath + bloqName);
    }
    void GetHasDebris(BloqReferences bloq)
    {
        bool hasLeft, hasRight;

        hasLeft  = bloq.transform.Find("LeftDebris") != null;
        hasRight = bloq.transform.Find("RightDebris") != null;

        bloq.config.hasDebris = hasLeft && hasRight;
    }
Beispiel #3
0
    void CopyBloqDescriptor()
    {
        BloqReferences reference = objectToCopy.GetComponent <BloqReferences>();

        if (!reference)
        {
            return;
        }

        Copy(reference.bmbfmod, reference.descriptor);
    }
    /// <summary>
    /// Runs the code to display the bmbf input options in the GUI
    /// </summary>
    /// <param name="bloq"></param>
    void BMBFConfigDisplay(BloqReferences bloq)
    {
        QosmeticUtils.addIfNull(bloq.bmbfmod);

        bloq.bmbfmod.components[0].type = "FileCopyMod";
        bloq.bmbfmod.components[0].targetRootedPathAndFileName = questPath + "testBloq." + extension;

        if (bloq.advancedInfo)
        {
            bloq.bmbfmod.coverImageFilename = EditorGUILayout.TextField("Cover image name", bloq.bmbfmod.coverImageFilename);
        }
        else if (bloq.bmbfmod.coverImageFilename == "" && exporterConfig.defaultCoverImageFileName != "")
        {
            bloq.bmbfmod.coverImageFilename = exporterConfig.defaultCoverImageFileName;
        }
        bloq.bmbfmod.icon = bloq.bmbfmod.coverImageFilename;

        if (bloq.advancedInfo)
        {
            bloq.bmbfmod.version = EditorGUILayout.TextField("Bloq version", bloq.bmbfmod.version);
        }
        else if (bloq.bmbfmod.version == "" && exporterConfig.defaultVersion != "")
        {
            bloq.bmbfmod.version = exporterConfig.defaultVersion;
        }

        if (bloq.advancedInfo)
        {
            bloq.bmbfmod.links.pageLink = EditorGUILayout.TextField("Page link", bloq.bmbfmod.links.pageLink);
        }
        else if (bloq.bmbfmod.links.pageLink == "" && exporterConfig.defaultPageLink != "")
        {
            bloq.bmbfmod.links.pageLink = exporterConfig.defaultPageLink;
        }

        bloq.bmbfmod.gameVersion    = EditorGUILayout.TextField("Game version", bloq.bmbfmod.gameVersion);
        bloq.bmbfmod.description[0] = EditorGUILayout.TextField("Description", bloq.bmbfmod.description[0]);
        bloq.bmbfmod.platform       = "Quest";
        bloq.bmbfmod.name           = EditorGUILayout.TextField("Bloq name", bloq.bmbfmod.name);
        bloq.bmbfmod.author         = EditorGUILayout.TextField("Author name", bloq.bmbfmod.author);
        bloq.bmbfmod.category       = "Bloq";

        bloq.bmbfmod.components[0].sourceFileName = bloq.bmbfmod.name + "." + extension;

        string modID = bloq.bmbfmod.name + bloq.bmbfmod.author + "V" + bloq.bmbfmod.version;

        modID = QosmeticUtils.sanitizeString(modID);

        bloq.bmbfmod.id = modID;
    }
    /// <summary>
    /// Exports a complete Zip package ready to be loaded into bmbf
    /// </summary>
    /// <param name="bloq"></param>
    void ExportBloqZip(BloqReferences bloq, string path = "")
    {
        /*
         * if (EditorUserBuildSettings.activeBuildTarget.ToString() != "Android")
         * {
         *  EditorUtility.DisplayDialog("Exportation Failed!", "Your projects build target is not Android.", "OK");
         *  return;
         * }
         */
        bool batch = path != "";

        GameObject bloqObject = bloq.gameObject;
        TextAsset  config     = new TextAsset(JsonUtility.ToJson(bloq.config, true));

        string    bmbfmodJson = JsonUtility.ToJson(bloq.bmbfmod, true);
        TextAsset bmbfmod     = new TextAsset(bmbfmodJson);

        string    descriptorString = JsonUtility.ToJson(bloq.descriptor, true);
        TextAsset descriptor       = new TextAsset(descriptorString);

        string zipname = bloq.bmbfmod.name + "V" + bloq.bmbfmod.version + ".zip";

        zipname = QosmeticUtils.sanitizeString(zipname);

        if (!batch)
        {
            path = EditorUtility.SaveFilePanel("Save " + "." + extension + " zip", "", zipname, "zip");
        }
        else
        {
            path += zipname;
        }

        if (path == "")
        {
            EditorUtility.DisplayDialog("Exportation Failed!", "Invalid path", "OK");
            return;
        }

        string fileName   = bloq.bmbfmod.name + "." + extension;
        string folderPath = Path.GetDirectoryName(path);

        string workingDir = Application.temporaryCachePath + "/QuestSaber";

        if (File.Exists(path))
        {
            File.Delete(path);
        }
        if (!Directory.Exists(workingDir))
        {
            Directory.CreateDirectory(workingDir);
        }

        if (exporterConfig.removeCamerasAtExport)
        {
            QosmeticUtils.PurgeCameras(bloqObject);
        }
        if (exporterConfig.removeLightsAtExport)
        {
            QosmeticUtils.PurgeLights(bloqObject);
        }

        Selection.activeObject = bloqObject;
        EditorUtility.SetDirty(bloq);
        EditorSceneManager.MarkSceneDirty(bloqObject.scene);
        EditorSceneManager.SaveScene(bloqObject.scene);

        GameObject camObject;
        Camera     exportCam;

        if (exporterConfig.allowOwnCamera) // manual cam
        {
            camObject = cam.gameObject;
            exportCam = cam;
        }
        else // automatic cam:
        {
            camObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
            exportCam = camObject.AddComponent <Camera>();
            exportCam.gameObject.name         = "Camera";
            exportCam.transform.localPosition = new Vector3(2.2f, 2.6f, -6.4f);
            exportCam.transform.rotation      = Quaternion.Euler(20.0f, -20.0f, 0.0f);
            exportCam.clearFlags      = CameraClearFlags.SolidColor;
            exportCam.backgroundColor = new Color(0.0f, 0.0f, 25.0f / 256.0f);
        }
        exportCam.nearClipPlane = 0.01f;

        int oldCamMask    = exportCam.cullingMask;
        int oldObjectMask = bloq.gameObject.layer;
        int newMask       = 31;
        int newCamMask    = 1 << 31;

        // moved prefab forward so that the layermask isnt f****d up on the actual exported file
        PrefabUtility.SaveAsPrefabAsset(Selection.activeGameObject as GameObject, "Assets/" + prefabName + ".prefab");

        if (exporterConfig.setCamLayerOnExport)
        {
            exportCam.cullingMask = newCamMask;
            QosmeticUtils.SetLayerRecursively(exportCam.gameObject, newMask);
            QosmeticUtils.SetLayerRecursively(bloq.gameObject, newMask);
        }

        Texture2D thumbnail = QosmeticUtils.getTexture2D(exportCam, 1024, 1024);


        //Start actually constructing the bundle


        AssetDatabase.CreateAsset(config, "Assets/config.asset");
        AssetDatabase.CreateAsset(bmbfmod, "Assets/BMBFmod.asset");
        AssetDatabase.CreateAsset(thumbnail, "Assets/thumbnail.asset");
        AssetDatabase.CreateAsset(descriptor, "Assets/descriptor.asset");

        AssetBundleBuild assetBundleBuild = default(AssetBundleBuild);

        assetBundleBuild.assetNames = new string[]
        {
            "Assets/" + prefabName + ".prefab",
            "Assets/config.asset",
            "Assets/BMBFmod.asset",
            "Assets/thumbnail.asset",
            "Assets/descriptor.asset"
        };

        assetBundleBuild.assetBundleName = fileName;

        BuildTargetGroup selectedBuildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
        BuildTarget      activeBuildTarget        = EditorUserBuildSettings.activeBuildTarget;

        //Build Bundle
        BuildPipeline.BuildAssetBundles(workingDir, new AssetBundleBuild[] { assetBundleBuild }, 0, BuildTarget.Android);
        EditorPrefs.SetString("currentBuildingAssetBundlePath", folderPath);
        EditorUserBuildSettings.SwitchActiveBuildTarget(selectedBuildTargetGroup, activeBuildTarget);



        Directory.CreateDirectory(workingDir + "/tempzip");

        QosmeticUtils.exportImage(thumbnail, workingDir + "/tempzip/" + bloq.bmbfmod.coverImageFilename);
        File.Move(workingDir + "/" + fileName, workingDir + "/tempzip/" + fileName);
        File.WriteAllText(workingDir + "/tempzip/bmbfmod.json", bmbfmodJson);

        QosmeticUtils.createZipFromFolder(workingDir + "/tempzip", path);

        //Asset cleanup
        AssetDatabase.DeleteAsset("Assets/" + prefabName + ".prefab");
        AssetDatabase.DeleteAsset("Assets/config.asset");
        AssetDatabase.DeleteAsset("Assets/BMBFmod.asset");
        AssetDatabase.DeleteAsset("Assets/thumbnail.asset");
        AssetDatabase.DeleteAsset("Assets/descriptor.asset");
        if (!exporterConfig.allowOwnCamera)
        {
            DestroyImmediate(camObject);
        }
        clearTemp(workingDir);

        AssetDatabase.Refresh();

        if (exporterConfig.setCamLayerOnExport)
        {
            if (exporterConfig.allowOwnCamera)
            {
                exportCam.cullingMask = oldCamMask;
            }
            if (exporterConfig.allowOwnCamera)
            {
                QosmeticUtils.SetLayerRecursively(exportCam.gameObject, oldObjectMask);
            }
            QosmeticUtils.SetLayerRecursively(bloq.gameObject, oldObjectMask);
        }
        if (!batch)
        {
            EditorUtility.DisplayDialog("Exportation Successful!", "Exportation Successful!", "OK");
            EditorUtility.RevealInFinder(path);
        }
    }
 void GetHasBomb(BloqReferences bloq)
 {
     bloq.config.hasBomb = bloq.transform.Find("Bomb") != null;
 }
 /// <summary>
 /// Runs the code to display the bloq input options in the GUI
 /// </summary>
 /// <param name="bloq"></param>
 void BloqConfigDisplay(BloqReferences bloq)
 {
     bloq.config.disableBaseGameArrows = EditorGUILayout.ToggleLeft("Disable Base Game Arrows", bloq.config.disableBaseGameArrows);
 }
 /// <summary>
 /// Runs the code to display the descriptor settings in the GUI
 /// </summary>
 /// <param name="bloq"></param>
 void DescriptorDisplay(BloqReferences bloq)
 {
     bloq.descriptor.objectName  = EditorGUILayout.TextField("Bloq name", bloq.descriptor.objectName);
     bloq.descriptor.authorName  = EditorGUILayout.TextField("Author name", bloq.descriptor.authorName);
     bloq.descriptor.description = EditorGUILayout.TextField("Description", bloq.descriptor.description);
 }
    bool shouldDisableExport(BloqReferences bloq)
    {
        bool disableExport = bloq.transform.Find("LeftArrow") == null || bloq.transform.Find("RightArrow") == null || bloq.transform.Find("LeftDot") == null || bloq.transform.Find("RightDot") == null;

        return(disableExport);
    }