Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Map xls to Scriptable Objects

Discussion in 'Scripting' started by juasanpar, Feb 16, 2018.

  1. juasanpar

    juasanpar

    Joined:
    Oct 5, 2017
    Posts:
    2
    Greetings, I'll explain my problem:

    I'm developing a board game that uses cards with text, as monopoly does for instance. Each card is created as a Scriptable Object so that I can add the text manually through the Unity editor and create the card object. The thing is I have a xls file with text for different cards in each row, having hundreds of lines which would take plenty of time to introduce by hand.

    Is there a way in which I could automatically create a SO from each row of the xls? Maybe the SO approach isn't very efficient here considering the format the data is stored?

    Thanks in advance.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    You write a function that does that, and call that function!

    If this is a one-off thing, I'd write a [MenuItem] command that parses the xls file and generates all of the corresponding ScriptableObjects. If you're doing this several times, I'd make an editor window that allows you to specify the path to the xls file and other options you want to have.

    Please ask if there's any part of the process you need help with. Your post is a bit vague about what you're not managing to do. Is it parsing the file, creating the SOs, storing the SOs, or what?

    In case it's creating the SO's, you can call ScriptableObject.CreateInstance<YourSoType>() to create it, set all the data you want on it from the xls, and then use AssetDatabase.CreateAsset to store that SO as a file in your project.
     
    juasanpar likes this.
  3. juasanpar

    juasanpar

    Joined:
    Oct 5, 2017
    Posts:
    2
    Yes sorry I forgot to specify. The problem was that, how to create the SO from a C# script, I'm in begginer using Unity at the moment. Thanks for the reply, I'll try your advice.