Misc

← Back Editor assembly guide

Mostly, database works inside Editor assembly the same way as it works at runtime, meaning you can develop your own Editor tools on top of the database. Use generated classes to access database. Below are useful code snippets. You may need to add the following lines to the top of your C# file so the code compiles.


using BansheeGz.BGDatabase;
using BansheeGz.BGDatabase.Editor;
Saving database

To save database in Unity Editor via C# code from Editor assembly, use this line:

    //This will work ONLY inside Unity Editor from Editor Assembly
    BGRepoSaver.SaveRepo();

To save database in Unity Editor via C# code from Runtime assembly, use this line:

    //This will work ONLY inside Unity Editor from Runtime or Editor Assembly
    BGUtil.SaveDatabaseInUnityEditor();
Assigning assets to asset fields

To assign unity asset field values, use SetAsset method, defined on each unity asset field and available in Editor assembly (this method is not available at runtime assembly)

    SetAsset(int entityIndex, UnityEngine.Object asset)

The method is defined at the base Unity asset field, which is BGFieldUnityAssetA<T> (T is the value type), so you need to downcast BGField to this class if you do not use CodeGen addon. If you use CodeGen addon, you can access the field directly without need to downcast, using {TableClass}._{fieldName} notation, see more details here

Ensuring the database is loaded
    if (!BGRepo.DefaultRepoLoaded) BGRepo.Load();
Running export/import job
    //find the job by it's name (replace SomeName with actual job's name)
    var job = BGSettingsEditor.Model.SyncList.Find(job => job.Name == "SomeName");
    //run the job (false is for import, true for export)
    BGSync.RunTask(job, false);
← Back to Misc