I’m using QuickSheet to make ScriptableObjects from xml files and access the data in Unity
I need a generic method for extracting the data because I have multiple spreadsheets.
Each spreadsheet has three columns: ID, EN, ES.
The script takes the ID and language code, then grabs the relevant data.
The problem I have is that I don’t know how to get an enum in a generic way (not even sure that’s what I need to do?!).
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[SerializeField] SerializedObjectSpreadshee serializedObjectSpreadshed;
public string GetData(int id, string languageCode)
{
List<SerializedObjectSpreadshedData> items = new List<SerializedObjectSpreadshedData>(); // 1 Make a list
items.AddRange(serializedObjectSpreadshed.dataArray); // 2 Add the SO data
AppleActionsData foundID = items.Find(x => x.ID[0] == id); // 4 Search for the ID and add it to a list
var foundAction = foundID.GetType().GetProperty(languageCode).GetValue(foundID, null); // 5 Get the language data from the element
var strings = ((IEnumerable)foundAction).Cast<object>() // 6 Convert language data to a string array
.Select(x => x == null ? x : x.ToString())
.ToArray();
return strings[0].ToString();
}