Search Unity

BG Database (inMemory database | Excel/Google Sheets syncing | CodeGen | Save/Load support)

Discussion in 'Assets and Asset Store' started by BansheeGz, May 3, 2018.

  1. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hi, your solution should work perfectly fine and probably the best one.
    Our asset does not use Newtonsoft.Json.dll directly, but it is included in GoogleSheets API library (which we use)
    I tried to use GoogleSheets API with JSON.NET from Asset Store and it worked without any issue.
     
    Last edited: Jan 28, 2020
    mike6502 likes this.
  2. BurmesterVR

    BurmesterVR

    Joined:
    Sep 9, 2016
    Posts:
    6
    Hello, we have a client that would like to be able to make occasional changes to the text displayed in a webgl project, so we are considering using your plugin along with google sheets for the setup to update the database on loading the webgl application. Due to the 500 read requests per 100 seconds limit, my question is, does your plugin pull in all of the data in a single request? We will probably have some 60 text strings we will need to pull in, so I'm hoping they could all be grabbed in a single request to google sheets, in which case this limit shouldn't be an issue.
     
  3. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hello, thank you for your interest in our asset

    1) Our LiveUpdate plugin ( https://www.bansheegz.com/BGDatabase/Addons/LiveUpdate/ ) uses exactly 1 request per table (no matter how many rows it has), 2 tables=2 requests etc.

    2) Some people reported they were able to increase free usage quota without creating billing account to 2500 requests per 100 seconds https://stackoverflow.com/a/48204596/1352958

    3) Each client sends its own request, so 100 clients updating 1 table=100 requests.
     
  4. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    Can you replicate in cs the "Get By Index" generated playmaker actions?
     
  5. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Code (CSharp):
    1.         [ActionCategory("BansheeGz")]
    2.         [HutongGames.PlayMaker.Tooltip("Fetch row data for MyTable meta from GameRepo database by row's index")]
    3.         public partial class MyTableGetByIndex : FsmStateAction
    4.         {
    5.             private static BansheeGz.BGDatabase.BGMetaRow _metaDefault;
    6.             public static BansheeGz.BGDatabase.BGMetaRow MetaDefault
    7.             {
    8.                 get
    9.                 {
    10.                     if(_metaDefault==null || _metaDefault.IsDeleted) _metaDefault=BGRepo.I.GetMeta<BansheeGz.BGDatabase.BGMetaRow>(new BGId(4650564587387139656,5790520138910642877));
    11.                     return _metaDefault;
    12.                 }
    13.             }
    14.             private static BansheeGz.BGDatabase.BGFieldEntityName _ufle12jhs77_name;
    15.             public static BansheeGz.BGDatabase.BGFieldEntityName _name
    16.             {
    17.                 get
    18.                 {
    19.                     if(_ufle12jhs77_name==null || _ufle12jhs77_name.IsDeleted) _ufle12jhs77_name=(BansheeGz.BGDatabase.BGFieldEntityName) MetaDefault.GetField(new BGId(4852341910933812809,17293514567767541685));
    20.                     return _ufle12jhs77_name;
    21.                 }
    22.             }
    23.             [RequiredField]
    24.             [HutongGames.PlayMaker.Tooltip("Entity index")]
    25.             public FsmInt _Index;
    26.             [UIHint(UIHint.Variable)]
    27.             public FsmString name;
    28.             [UIHint(UIHint.Variable)]
    29.             [HutongGames.PlayMaker.Tooltip("Entity id")]
    30.             public FsmString _Id;
    31.             public override void Reset()
    32.             {
    33.                 _Id = null;
    34.                 _Index = null;
    35.                 name = null;
    36.             }
    37.             public override void OnEnter()
    38.             {
    39.                 if (_Index.IsNone)
    40.                 {
    41.                     Debug.LogWarning("Required field _Index is not set");
    42.                     return;
    43.                 }
    44.                 var index = _Index.Value;
    45.                 if(!_Id.IsNone)
    46.                 {
    47.                     _Id.Value = MetaDefault.GetEntity(index).Id.ToString();
    48.                 }
    49.                 if(!name.IsNone)
    50.                 {
    51.                     name.Value = _name[index];
    52.                 }
    53.                 Finish();
    54.             }
    55.         }
    56.  
    More examples are available here: https://www.bansheegz.com/BGDatabase/ThirdParty/Playmaker/ (at the bottom of the page)
     
  6. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    You just pasted the action. Doesnt matter.
    Honestly, Im finding the documentation really hard to follow.
     
  7. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    I would really appreciate it if you let me know which parts of our documentation could be improved

    I'm sorry I did not understand your question.
    Our C# API is very simple- there are literally 3-4 classes and 7-8 methods which cover 95% of all use-cases.
    On top of this API- there are generated classes, which are highly recommended, cause we can get rid of all boilerplate code by using them.

    In a very basic scenario (like Playmaker GetByIndex action), we need to
    1. Get a reference to the table
    2. Find the target row using a table reference
    3. Read/Write field values using a row reference
    Without code generation, these steps can be implemented like this:
    Code (CSharp):
    1.        //=========== Step 1. get reference to the table (YourTableName is a table name)
    2.         BGMetaEntity table = BGRepo.I["YourTableName"];
    3.  
    4.         //=========== Step 2. get reference to the target row using table reference
    5.         // Option 1) by row index (the first row)
    6.         BGEntity rowByIndex = table.GetEntity(0);
    7.  
    8.         // Option 2) by row id ("M8PlyZIMz0ian2012w564g" is ID)
    9.         BGEntity rowById = table.GetEntity(new BGId("M8PlyZIMz0ian2012w564g"));
    10.  
    11.         // Option 3) by row name ("RowName" is row's name)
    12.         BGEntity rowByName = table.GetEntity("RowName");
    13.  
    14.         // Option 4) by using search method (we search the entity which name=="RowName")
    15.         BGEntity rowBySearch = table.FindEntity(entity =>entity.Name == "RowName");
    16.  
    17.         //=========== Step 3. getting and setting fields (columns) values for selected row
    18.         // reading field value (we read field with name="intField" and type=int)
    19.         int intFieldValue = rowByIndex.Get<int>("intField");
    20.  
    21.         //writing field value (we write field with name="intField" and type=int)
    22.         rowByIndex.Set<int>("intField", intFieldValue + 1);
    The same steps with code generation:
    Code (CSharp):
    1.         //=========== Step 1. Not required, cause you can access the table directly by using generated class
    2.      
    3.         //=========== Step 2. get reference to the target row using table reference
    4.         YourTableName rowByIndex = YourTableName.GetEntity(0);
    5.         YourTableName rowById = YourTableName.GetEntity(new BGId("M8PlyZIMz0ian2012w564g"));
    6.         YourTableName rowByName = YourTableName.GetEntity("RowName");
    7.         YourTableName rowBySearch = YourTableName.FindEntity(entity => entity.Name == "RowName");
    8.      
    9.         //=========== Step 3. getting and setting fields (columns) values for selected row
    10.         int intFieldValue = rowByIndex.intField;
    11.         rowByIndex.intField = intFieldValue + 1;
    So, when we use code generation, we
    1. Skipping step 1 (getting a reference to a table)
    2. Do not provide field type
    3. Do not provide field name (because we use generated properties)
    4. We have compile-time check if all fields/tables references have proper names/types
    So I would always use code generation.

    Implementing Playmaker GetByIndex action (without code generation):
    Code (CSharp):
    1.         //get reference to the table
    2.         BGMetaEntity table = BGRepo.I["YourTableName"];
    3.         //get reference to the row (index=0)
    4.         BGEntity rowByIndex = table.GetEntity(0);
    5.         //reading int field "intField"
    6.         int intFieldValue = rowByIndex.Get<int>("intField");
    7.         //etc.
    8.  
    with code generation:
    Code (CSharp):
    1.         YourTableName rowByIndex = YourTableName.GetEntity(0);
    2.         int intFieldValue = rowByIndex.intField;
    3.         //etc.
    4.  
    More information about code generation: https://www.bansheegz.com/BGDatabase/CodeGeneration/ExtensionClasses/
    More information about our API: https://www.bansheegz.com/BGDatabase/API/
    We updated our "Code examples" page here: https://www.bansheegz.com/BGDatabase/CodeExamples/
    The code from this page can be executed by copying to Start() method of some MonoBehaviour script, attaching this script to some GameObject and running the scene. The code will be executed and results can be reviewed in the database window.

    Please, let me know if you have any questions
     
  8. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    I think is a mix between me pretending knowing more than I actually do and that your docs are not ready for newbies.
    Thanks for your answer, will study it carefully and come back again if Im still stuck!
     
    xpxilom likes this.
  9. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Please, do not hesitate to write to our support email directly: support@bansheegz.com
    Any feedback would be greatly appreciated
     
  10. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    So Im gettting it but the "intField" is giving me error. What i have is the straight the name of the field showing up, in my case ".f_name". Is this due this?

     
  11. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Settings parameters on the screenshot look fine.
    If you have "intField" in "YouTableName" table, the generated property for this field should be c_YouTableName .f_intField
    1) Generated class name is c_YouTableName (c_ is class name prefix from settings and YouTableName- is table's name )
    2) f_intField - is generated property (f_ is field name prefix and intField- is field's name)

    c_YouTableName.f_name- is generated property for "name" field
    I have attached generated dbGeneratedCOde.cs script (It works fine for me without any error)




    About the error- is this error is printed to the console?
    If yes- could you please post it here?
     

    Attached Files:

  12. AdrianoDeRegino

    AdrianoDeRegino

    Joined:
    Aug 10, 2019
    Posts:
    87
    Hi Miss.
    The feature: "Runtime (playmode) changes saving", is possible with bolt nodes?
    Thank you.
     
  13. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hi, yes, we created custom nodes for Bolt for saving/loading.
    You can download it here: https://www.bansheegz.com/BGDatabase/Downloads/ (Section 5 -Save/Load actions for Playmaker/Bolt)
     
    AdrianoDeRegino likes this.
  14. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    using code generation, can you explain me how to sort table fields with concrete examples? int columns, string columns etc. Thanks for your patience.
     
  15. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hi, let's say, you have MyTable table with (name:string, intField:int) fields and you don't use class/fields name prefixes in CodeGeneration settings, so your generated class name is the same as your table name and your properties names are the same as field names


    and you want to sort rows by intField, the code would be:
    Code (CSharp):
    1.         var result = MyTable.FindEntities(null, null, (e1, e2) => e1.intField.CompareTo(e2.intField));
    We use FindEntities generated static method and as the third parameter, we pass Comparison<MyTable> delegate, which is used to sort the rows.


    You can find more information about Comparison<T> delegate here: https://docs.microsoft.com/en-us/dotnet/api/system.comparison-1?view=netframework-4.8

    Another example: let's say you want to sort by string name field, the implementation would be:
    Code (CSharp):
    1. var result = MyTable.FindEntities(null, null, (e1, e2) => string.CompareOrdinal(e1.name,e2.name));
     
  16. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    I was indeed checking that microsoft web. Ill make that work. Many thanks!!
     
    BansheeGz likes this.
  17. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    How to do a relation between two tables? For example, one table containing "Countries" and another one containing "Cities". DO I have to do this manually?
     
  18. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    You need to add a "country" field to "Cities" table.
    Set field's type to "Relation->RelationSingle" and "Related" parameter to "Countries"



     
  19. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    That worked perfectly, and im able to fetch the reference column data.
    Many thanks!
     
  20. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    Is there a way to choose which column to show in the relation? Now its showing only "name" column.
     
  21. AdrianoDeRegino

    AdrianoDeRegino

    Joined:
    Aug 10, 2019
    Posts:
    87
    Hi again Mss.
    Sorry to bother you, but If i bought DG Database for 30 usd, is it possible to buy localization for 10 later? how?
     
  22. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Sorry for the late response, I did not receive an email notification and noticed your message only a little while ago

    Yes, you can choose which column to use as a name.
    Create a field you'd like to use as a name and toggle "Is name" on as shown on the screenshot below.
    The field should have "string" type
     
  23. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hi, sorry for the late response, I did not receive an email notification and noticed your message only a little while ago

    10$ upgrade to BGLocalization is available for every BGDatabase owner.
    Once you buy BGDatabase, BGLocalization will be available for 10 $ on the AssetStore page

     
    AdrianoDeRegino and MrIconic like this.
  24. MrIconic

    MrIconic

    Joined:
    Apr 5, 2013
    Posts:
    239
    Importing BGDatabase required me to delete newtonsoft dll (or not import it) due to already having one in my project.

    However, the Google API files had errors that state it could cause runtime issues. I don't need Google Export/Import.

    1) Can I just delete all the google files or will it break the asset somewhere?

    2) Can the newtonsoft file not be a direct file dependency so I could use one already in my project?
    2a) Do you know if deleting the supplied newtonsoft file breaks anything else? It seems to work fine so far but haven't built the project yet.
     
  25. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    If you do not need GoogleSheets integration, you can safely delete all GoogleSheets related DLLs (including newtonsoft dll)
    Delete these folders:
    1) Assets\BansheeGz\BGDatabase\Editor\Libs\GDataV4
    2) Assets\BansheeGz\BGDatabase\Editor\Pluginz\

    It won't break or affect anything (except GoogleSheets integration inside Unity Editor)

    If you use Newtonsoft.Json.dll from JSON.NET package (this one https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347#content ) then yes, you can use it instead of Newtonsoft.Json.dll, which is bundled with our package.
    We have tested it earlier and it worked ok
    Delete duplicate DLL file from our package- Assets\BansheeGz\BGDatabase\Editor\Libs\GDataV4\Newtonsoft.Json.dll
    Everything should work fine (including GoogleSheets integration)

    No, deleting Newtonsoft.Json.dll library should not affect anything, except GoogleSheets integration.
    If you delete all Newtonsoft.Json.dll files from your project- you will get an error while trying to run export/import to GoogleSheets inside Unity Editor and this will be the only affected feature.

    Also, our DLL for runtime assembly (BGDatabase.dll) has zero dependency- it does not require any DLL.
    All DLLs, bundled with our package (GoogleSheets and Excel libraries), are required for Editor assembly only (BGDatabaseEditor.dll).
     
    Last edited: Apr 9, 2020
    MrIconic likes this.
  26. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    I think every - icon (minus icon) needs a pop up window letting user know he is deleting whatever.
     
  27. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Thank you for the suggestion
    I sent an upgraded package to you in private message
     
    StupydHors likes this.
  28. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    Hi! Is there a way to enter formatted text in a string field? Right now that text is showed as a single line when displayed.
     
  29. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hi, there are 2 different fields for string values:
    1) string -for a single line string value
    2) text- for multiple lines string value
     
    MrIconic likes this.
  30. AdrianoDeRegino

    AdrianoDeRegino

    Joined:
    Aug 10, 2019
    Posts:
    87
    Hi, I already have Newtonsoft.Json.dll on my project, and now with BG Database I´m having errors, cause now there are 2 of them, would you mind helping me dealing with it?

    My scripts are giving this error:
    CB_CmdEventColl.cs(7,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
     
  31. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hi,

    Please, delete Newtonsoft.Json.dll, which is bundled with our package (Assets\BansheeGz\BGDatabase\Editor\Libs\GDataV4\Newtonsoft.Json.dll).

    Or , alternatively, select this DLL file in the Project view, uncheck "Editor" toggle in the Inspector and press on "Apply" button (as shown on the screenshot below)

     
  32. StupydHors

    StupydHors

    Joined:
    Oct 25, 2016
    Posts:
    25
    Small bug with Validation. It seem unable to detect references to addresable files. See picture.
    Another "bug" - When you have "Entity name is unique" bool checked and enter duplicate names, instead of the error appearing in Database tab it appears in Configuration tab and weirdest of all Scene Explorer type.

    PS: maybe I missed it but Im unable to find documantation for "Entity is singleton" and "Entity name is empty" checkboxes. ("Entity name is unique" is pretty self explenatory)

    PPS: Not sure if there is a reason for this. But if you have Relation:Multiple that is empty. Instead of an empty list you get back null. (totally un-initialized) This might not be desirable as additional null checks are then nessesary.
     

    Attached Files:

    Last edited: May 12, 2020
    BansheeGz likes this.
  33. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Thank you for reporting the issues- I've sent an updated package to you in private message

    We have created a draft for doc page here: https://www.bansheegz.com/BGDatabase/Drafts/index.html

    It's intended behaviour, cause null value has the same effect as an empty list, meaning there is no value set.
    If there is no value- there is no reason (apart from getting rid of additional null check) to create an empty list, cause it takes resources (memory and CPU)
     
    StupydHors likes this.
  34. StupydHors

    StupydHors

    Joined:
    Oct 25, 2016
    Posts:
    25
    Additional question. I am serializing DBE_*stuff* into a Json on my own. Currently what Im saving is the ID field from the database. Do you think its a good idea to serialize the *name* field instead?
    Why Im asking is. What if one of our designers removes an item and then re-enters it. The item would get a new ID and not load properly if a user then updates their game. I think it should be totaly fine. Especialy with "entity name is unique" checked. Am I missing something that makes this a horrible idea?
     
  35. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    In general, using ID as a primary key for a row is a more robust approach, but if you want to use a name as a primary key- I think it can be implemented with some restrictions.
    Some implications of using a name as a primary key are:
    1) You need to ensure name value is unique
    2) If you want to change the name after you serialized data to JSON, you need to change it in both places- in json and in the database, otherwise, a link between JSON object and database row will be lost.
    3) As you already mentioned, if you delete a row and after that create a new one with the same name- it will be the same row for your serialization system- but for the database, it will be 2 different rows and all references to the old row will be lost.
    We use ID as a row reference in a lot of places:
    1) Data binders
    2) BGEntityGo component (and generated subclasses)
    3) Export/Import to excel/google sheets
    4) SaveLoad addon
    5) In "Relation" fields (single/multiple)
    6) GetById/SetById actions/units for Playmaker/Bolt
    So if you use any of the above functionality and you reference some rows - you can not delete these rows and create them again without losing references.
    Also, some additional restrictions may be caused by your particular workflow.
    I'm not sure if I understand correctly why you want to serialize data to JSON-the only possible reason that came to my mind is the ability to edit data in external tools
     
    StupydHors likes this.
  36. StupydHors

    StupydHors

    Joined:
    Oct 25, 2016
    Posts:
    25
    2) thats what Im after. The rows which I want to save are in general the final data. As in -> they contain references to other rows but nothing contains a reference to them.

    Why? Well. Im mainly using the database for data entry. I find in much more pleasant than having to write editor extensions for scriptable objects etc... As Im using it the database only contains static data. User specific data is then serialized to JSON. 2 reasons for this. Ad1) speed. Ad2) security. I have total control over encription and I imagin saving the player inventory with possibly hundreds of items and then trying to modify that Meta table would not be as fast as just saving to JSON.
     
  37. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    If
    1) Nothing reference the rows you want to export to JSON
    2) No need to update names after exporting
    - I do not see any reason why using names as primary keys should not work

    For example,
    1) You have a static list of items in your database (Sword1, Spear1 etc.) along with their attributes
    2) Your inventory system does not use the database to store inventory items
    3) Each inventory slot has a reference to one of the items from the database,
    so your JSON data looks like this:
    Code (CSharp):
    1. {
    2.   "slot": "slot1" // this is a string primary key for 1st inventory slot
    3.   "item": "7F9isnWlRUiA/P9e3CDA6g" // this is a reference (ID) to item from database
    4.   "quantity" : 1 // number of items
    5. }
    6. ..etc
    I think it should work just fine

    But if it were not an example- I would replace slot name with slot number and used this number as a primary key or removed slot attribute and used array index as a slot number
     
  38. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14
    Hi, first this asset is great!!
    But, I have a one question about BG Database.
    Is there a way to use enum as a key directly in table?
     
  39. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hi, thank you for your support!

    Do you mean using enum field as a unique key for a row and accessing this row directly using enum value?



    Something like this?

    Code (CSharp):
    1.         BGMetaEntity table = BGRepo.I["test"];
    2.         BGEntity zeroRow = table.SomeMethodToGetTheRowByEnum(MyEnum.Zero);
    3.  
     
  40. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14

    yes! that's what i want
     
  41. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Currently, it's not directly supported, unfortunately, but we will consider adding such feature to one of the future releases.

    A workaround is:
    option #1: Create an extension method (if you do not use code generation addon)
    option #2: Create a partial class with the same name as the generated class and add an additional method to it (if you use code generation addon)
    We highly recommend to use code generation addon. (https://www.bansheegz.com/BGDatabase/Addons/CodeGeneration/)

    Option #1 (without addon):
    Code (CSharp):
    1. public static class BGMetaEntityExtensions
    2. {
    3.     public static BGEntity GetByEnum<T>(this BGMetaEntity meta, T value) where T : Enum
    4.     {
    5.         var targetField = meta.FindField(field => field is BGFieldEnum enumField && enumField.EnumType==typeof(T)) as BGFieldEnum;
    6.         if (targetField == null) throw new Exception($"Table {meta.Name} does not have an enum field with {typeof(T)} enum type");
    7.         return meta.FindEntity(entity => Equals(targetField[entity.Index], value));
    8.     }
    9. }
    use it like this:
    Code (CSharp):
    1.         BGMetaEntity table = BGRepo.I["test"];
    2.         BGEntity firstRow = table.GetByEnum(MyEnum.First);
    3.  
    Option #2 (with addon- I assume you leave class/field prefixes empty in CodeGen addon settings):
    Code (CSharp):
    1. public partial class test : BGEntity
    2. {
    3.     public static test GetByEnum(MyEnum value)
    4.     {
    5.         return FindEntity(entity => Equals(_MyEnum[entity.Index], value));
    6.     }
    7. }
    use it like this:
    Code (CSharp):
    1. test firstRow = test.GetByEnum(MyEnum.First);
    Any other additional methods can also be added using the same techniques
     
  42. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14


    Thanks for the quick response.
    It has helped a lot. :)
    I hope that will be suported soon.

    Anyway I'm wandering about the search time complexity of the existing method of using string keys.
    Is it O(1)?
     
  43. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    GetById/GetByName/GetByIndex methods has O(1) complexity

    Code (CSharp):
    1.         table.GetEntity(new BGId("someId"));
    2.         table.GetEntity("some name");
    3.         table.GetEntity(1);
    GetByIndex is the fastest way
    GetByKey will also have O(1) complexity (when we add it- like GetById/GetByName)

    Also, another option for accessing the rows:
    1) If you mark the table as having the rows with unique names (as shown on the screenshot below)
    2) If you add "Entity prefix" to CodeGen addon settings (let's say "E_")
    3) If you enter unique names for the rows

    Code gen addon will generate a separate property for each entity (using E_{row's name} as C# identifier)- and you can access rows directly with generated properties and O(1) search complexity like this:
    Code (CSharp):
    1. test firstRow = test.E_First;
     
    StupydHors likes this.
  44. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14
    Thank you so much!! :):)
     
  45. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14
    Hello,
    I'm wondering about the function of "Is name?" boolean value.
    I thought it made the field as a Name.
    But I can't use meta[OwnFieldName] or meta.getEntity(OwnFieldName) when I checked it in my string field.
     
  46. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    Hello, "Is name?" parameter is used only inside Unity Editor.
    For example, It allows overriding which field is shown when you select a related entity for relations fields.
    We are already working on GetByKey(s) implementation, I will send an upgraded package to you in a private message as soon as it's ready (most probably during this week)
     
  47. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14
    Oh, that's really good news!
    Thank you for all your helf.
     
  48. StupydHors

    StupydHors

    Joined:
    Oct 25, 2016
    Posts:
    25
    The package with fixed validation is working perfectly. Thank you so much for that.
    I feel like Im making such tedious requests but... would if be possible for the database to automaticaly copy the "Sprite" out of a Texture2D asset. Currently if you have a Texture2D asset you need to "open it" and then you can select the sprite drag in into the database. This is such a small request. But with 150+ items. It would save me a lot of clicking.

    Another probably not so small request to save a lot of clicking. Default values. Atleast for primitives. Like bools and ints.

    Thank you. Still the best asset I ever tried.
     
    Last edited: May 29, 2020
    BansheeGz likes this.
  49. BansheeGz

    BansheeGz

    Joined:
    Dec 17, 2016
    Posts:
    370
    We've added this feature- I've sent you a private message with the package
    This is a really great idea of supporting dragging textures to sprite fields, I regret we did not implement it earlier
    Thank you so much for supporting us and helping us to improve the asset

    I think it's already implemented.
    You can find default value for a field under Configuration tab (as shown on the screenshot below).
    Use a string representation of field value
    If you are not sure what is correct string format- export data to Excel or Google Sheets
    Please, let me know if you have any question

     
  50. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14
    Hellow,
    I want to update database on the player's device without new build.
    So I'm trying to use unity's addressable.
    Can the database be used as an addressables bundle?