Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[RELEASED] Databox - Data editor & save solution

Discussion in 'Assets and Asset Store' started by propeller, Oct 30, 2019.

  1. propeller

    propeller

    Joined:
    Jul 2, 2012
    Posts:
    237
    Did you update to the newest version? Databox does not save the data to an asset... it uses Odin or FullSerializer to save all the data to a file (json or binary)

    Please follow the installation instructions:
    http://databox.doorfortyfour.com/documentation/getting_started


    Hi sorry for not being so active here!
    Unfortunately the forum refuses to notify me about new posts.
    You can also join the Discord server: https://discord.gg/a5uf3nM

    I'm more active here and you can also get help from the community :)



    A Databox object is already a scriptable object. Not sure why you want to add and nest it in another scriptable object?
    The idea of copying the data to the persistent data folder is to make sure the user has got all the data on his machine. So when modifying values it will be saved on the users machine. This is important because when updating your game the saved data will remain in the persistent data folder. Streaming Assets would replace the saved values on the users machine, when the game gets updated.
     
    MrIconic likes this.
  2. peeka

    peeka

    Joined:
    Dec 3, 2014
    Posts:
    105
    can you add support for ulongtype? or would it work if I add it myself? why is it missing in the first place?
     
  3. Sky_Higher

    Sky_Higher

    Joined:
    Sep 29, 2017
    Posts:
    2
  4. burlingk

    burlingk

    Joined:
    Dec 28, 2014
    Posts:
    2
    Something I have not found stated anywhere, one way or the other: Does Databox support Linux? Can I use this in a project that is intended to support Linux as well as Windows?

    Thanks!
     
  5. oliverashford

    oliverashford

    Joined:
    Jan 27, 2016
    Posts:
    3
    I have recently purchased Databox and it is working great - the documentation has got me up and running with some basic examples quickly. Appreciate the great resource!

    I am creating a choose your own adventure game and am storing the immutable 'book' data in Databox. Previously I have been hand writing all the content in JSON then parsing in Unity and building nested, custom objects. What I really want to do is use Databox as an 'in unity' editor for this content. This will require me to create nested custom classes to be serialised by Databox and displayed in the Unity UI - is this possible?

    An simple pseudo code example of my structure:

    Code (JavaScript):
    1.  
    2. {
    3.     "bookTitle": "The Wizard Of Firetop Mountain",
    4.     "pages": [
    5.         {
    6.             "pageRefId": 0,
    7.             "pageTitle": "Rumours",
    8.             "pageAmbientAudio": "pageAmbientAudio_forest",
    9.             "pageText": [
    10.                 "Only a foolhardy adventurer..."
    11.             ],
    12.             "pageOptions": [
    13.                 {
    14.                     "optionText": "Now Turn over",
    15.                     "optionType": "New Page",
    16.                     "optionTarget": 1
    17.                 }
    18.             ]
    19.         },
    20.         {
    21.             "pageRefId": 156,
    22.             "pageAmbientAudio": "pageAmbientAudio_cave",
    23.             "pageText": [
    24.                 "You charge the door with your shoulder."
    25.             ],
    26.             "pageOptions": [
    27.                 {
    28.                     "optionText": "Charge!",
    29.                     "optionType": "Test"
    30.                 }
    31.             ],
    32.             "pageAction": {
    33.                 "actionText": "Roll two dice. If the number rolled is less than or equal to your skill score, you succeed. If the number rolled is greater than your skill, you rub your bruised shoulder and decide against trying again. You return to the junction.",
    34.                 "actionType": {
    35.                     "actionDice": "Two Dice Roll",
    36.                     "actionAgainst": "Skill",
    37.                     "actionOperator": "Less Than Or Equal"
    38.                 },
    39.                 "actionResult": {
    40.                     "actionPassed": 343,
    41.                     "actionFailed": 92
    42.                 }
    43.             }
    44.         },
    45.         {
    46.             "pageRefId": 248,
    47.             "pageAmbientAudio": "pageAmbientAudio_cave",
    48.             "pageText": [
    49.                 "The creature that has just awakened is an ORC! He scrambles to his feet and turns to grasp at a rope which is probably the alarm bell. You must attack him quickly."
    50.             ],
    51.             "pageOptions": [
    52.                 {
    53.                     "optionText": "Attack!",
    54.                     "optionType": "Battle"
    55.                 }
    56.             ],
    57.             "pageBattle": {
    58.                 "battleEnemies": [
    59.                     {
    60.                       "enemyName": "Orc",
    61.                       "Skill": 6,
    62.                       "Stamina": 5
    63.                     }
    64.                 ],
    65.                 "battleResult": {
    66.                     "battlePassed": 301
    67.                 }
    68.             }
    69.         },
    70.         {
    71.             "pageRefId": 278,
    72.             "pageAmbientAudio": "pageAmbientAudio_cave",
    73.             "pageText": [
    74.                 "The passageway soon comes to an end at a locked wooden door. You listen at the door but hear nothing. Will you try to charge the door down or would you rather turn around and go back to the junction?"
    75.             ],
    76.             "pageOptions": [
    77.                 {
    78.                     "optionText": "Charge door down",
    79.                     "optionType": "New Page",
    80.                     "optionTarget": 156
    81.                 },
    82.                 {
    83.                     "optionText": "Turn around",
    84.                     "optionType": "New Page",
    85.                     "optionTarget": 92
    86.                 }
    87.             ]
    88.         },
    89.         {
    90.             "pageRefId": 301,
    91.             "pageAmbientAudio": "pageAmbientAudio_cave",
    92.             "pageText": [
    93.                 "To your left, on the west face of the passage, there is a rough-cut wooden door. You listen at the door and can hear a rasping sound which may be some sort of creature snoring. Do you want to open the door?"
    94.             ],
    95.             "pageOptions": [
    96.                 {
    97.                     "optionText": "Open the door",
    98.                     "optionType": "New Page",
    99.                     "optionTarget": 82
    100.                 },
    101.                 {
    102.                     "optionText": "Press on northwards",
    103.                     "optionType": "New Page",
    104.                     "optionTarget": 208
    105.                 }
    106.             ]
    107.         }
    108.     ]
    109. }
    110.  
    111.  
    As far as I understand it in Databox this would require me to setup something like this:
    • Add Databox
    • Add Table: "Pages"
    • Define custom class: "Page" with vars:
      • id - int
      • text - string -> TextArea
      • ambient_audio - AudioClip -> ObjectField
      • options - An Array/Dictionary of "Option" objects, another custom class
    And it's there that I get stuck - I don't have much experience with building editor extensions in Unity. I know what I want is a tree like nesting of Pages -> Options, Page -> Battle -> Enemies. Is this possible or am I trying to make Databox do something it's not designed for? Would Odin alone be a better / simpler solution?

    Any help greatly appreciated (apologies for the long post!)
     
  6. propeller

    propeller

    Joined:
    Jul 2, 2012
    Posts:
    237
    Hi,
    first of all I'm happy to hear you like Databox. :)
    Figuring out how to structure data is always a challenge, but yes you could use List or Dictionary of classes as long as they are serializeable.
    So basically you create a custom base class which inherits from DataboxType.
    In this base class you then have your Dictionaries or Lists which holds other classes.
    Of course you will then have to create the editor UI to draw the data correctly in Databox by yourself. There are some example types (also lists and dictionaries) which should point you in the right direction.

    You can also write me an email if you need further support.
     
    oliverashford likes this.
  7. oliverashford

    oliverashford

    Joined:
    Jan 27, 2016
    Posts:
    3
    Thanks for getting back to me - that was really helpful. Have that issue sorted now.
     
  8. oliverashford

    oliverashford

    Joined:
    Jan 27, 2016
    Posts:
    3
    Hi,

    A question about serialising AudioClips. I have this code:

    Code (CSharp):
    1. [SerializeField]
    2. private AudioClip _ambientAudio;
    3. public AudioClip AmbientAudio
    4. {
    5.     get { return _ambientAudio; }
    6.     set
    7.     {
    8.         if (value == _ambientAudio) { return; }
    9.  
    10.         _ambientAudio = value;
    11.  
    12.         if (OnValueChanged != null) { OnValueChanged(this); }
    13.     }
    14. }
    And then to 'draw' the GUI:

    Code (CSharp):
    1. // Draw AmbientAudio
    2. using (new GUILayout.HorizontalScope())
    3. {
    4.     #if UNITY_EDITOR
    5.         _ambientAudio = (AudioClip)EditorGUILayout.ObjectField(_ambientAudio, typeof(AudioClip), true);
    6.     #endif
    7. }
    This works for selecting the AudioClip in the Databox inspector but it isn't saving the value. I presume this is because, as it is json/text we need to save a resource path, name or reference as opposed to binary sound data... how do I do this?

    Thanks in advance.
     
  9. propeller

    propeller

    Joined:
    Jul 2, 2012
    Posts:
    237

    Yes, exactly. If you want to use the resource path you'll have to store the resource path of the asset as a string. You can have a look at the built-in ResourcesType which does exactly this.
    If you're using the new Unity addressables, you can also use the AddressablesType. -> You'll have to uncomment the code from the AddressablesType.cs file.
     
    oliverashford likes this.
  10. Skotrap7

    Skotrap7

    Joined:
    May 24, 2018
    Posts:
    90
    Hi, I have a bunch of scriptable objects already defined (and some assets of those types) and I'm trying to switch over to using Databox. On the store page and documentation I see Scriptable Object mentioned a lot, but I don't see a clear way on how to use them with Databox.

    Do I need to abandon my scriptableobject classes and make them inherit from "DataboxType" instead? Or can I somehow have Databox serialize/deserialize data in and out of the scriptable objects?

    For the assets I can write a script to load them and save them in Databox, but I didn't want to make any changes to those classes until I knew what the right way to move forward here was.

    Lastly, my understanding of the entryid and valueid fields is that the entryid is a collection of a specific type and valueid is the items in the collection. Does that sound right?

    Thanks in advance!
     
  11. SweetBro

    SweetBro

    Joined:
    Jan 14, 2013
    Posts:
    63
    I see databox uses custom DrawEditor() to render custom classes. Is this compatible with Odin Inspector's editor rendering and if so is there a quick example you can show for a simple class consisting of just a foo/bar string?

    Essentially I want to make use of Odin's default rending for a lot of common fields so I don't have to constantly manually update draw logic to reflect changes in the data model.
     
  12. propeller

    propeller

    Joined:
    Jul 2, 2012
    Posts:
    237
    Let me try to explain it a bit more in detail:
    So with Databox you create a Databox object which is a scriptable object asset.
    Inside of this Databox object you can add your data. This data can be custom classes, but they have to derive from DataboxType. All data inside of a Databox object is then serialized to a file. So to answer your first question: Yes you would have to derive your custom classes from DataboxType in order to add them to a Databox object.

    An entry is a collection of different types and values are the actual "variables" containing value.
    Example: Entry -> Player
    Player entry has multiple different values like: Health (int), Name (string) etc.
     
  13. propeller

    propeller

    Joined:
    Jul 2, 2012
    Posts:
    237
    Unfortunately odin inspector is not supported. And I'm not sure if I could ever make it work with Databox.
    I plan to add some custom variable attributes to quickly draw custom editor gui though.
     
  14. Skotrap7

    Skotrap7

    Joined:
    May 24, 2018
    Posts:
    90
    Hey thanks for the reply, this helps a lot and gives me a path forward.
     
unityunity