How to run
If you need to run a job via C# code, use the following code
using System;
using BansheeGz.BGDatabase;
using BansheeGz.BGDatabase.Editor;
using UnityEditor;
//1) Put this file into Unity Editor Assembly (under Editor folder)
//2) Run JobsManager.RunTask method to launch export or import job
//3) Parameter jobName is the case-sensitive name of the job. It can be found under Export/import->Jobs
//4) Parameter isExport- If set to true, the export will be executed. If false, the import will be executed.
public static class JobsManager
{
// [MenuItem("Tools/Test export import")]
// private static void Test() => BGEditorUtility.CatchException(() => RunTask("excel", false)); //<- for testing
public static void RunTask(string jobName, bool isExport)
{
//load database if it's not already loaded
if (!BGRepo.DefaultRepoLoaded) BGRepo.Load();
//throw an exception if database can not be loaded
if (!BGRepo.Ok) throw new Exception($"Database can not be loaded, error={BGRepo.DefaultRepoErrorOnLoad}");
//check if settings are properly loaded
if (!BGSettingsEditor.OkWithLoad) throw new Exception("Can not load settings file");
//find target job
var job = BGSettingsEditor.Model.SyncList.Find(m => m.Name == jobName);
//check if the job was successfully found
if (job == null) throw new Exception($"Can not find a job with name {jobName}");
//run the job. Passing BGRepoSaver.SaveAndMarkAsSaved method to onSuccess parameter also saves the database and marks the database as saved
BGSync.RunTask(job, isExport, null, BGRepoSaver.SaveAndMarkAsSaved);
}
}