Talents = new List The Definition: Example Data: The Identifying SubRows Processing Main Rows Processing SubRows[CreateAssetMenu(menuName = "Create TalentsDatabase", fileName = "TalentsDatabase", order = 0)]
public class TalentsDatabase : ParsedScriptableObject
{
public List<Talent> Talents = new List<Talent>();
protected override void PopulateData(ParsedDataList data)
{
if (data.TryGetParsedData(0, out var talentsData))
{
EasyParser.ParseSubRowsData(talentsData, Talents, (row, subRow, index) =>
{
var talent = new Talent
{
Id = talentsData.GetString(row, 0),
Name = talentsData.GetString(row, 1),
Chance = talentsData.GetFloat(row, 2),
Cooldown = talentsData.GetFloat(row, 3),
Duration = talentsData.GetFloat(row, 4),
Cost = talentsData.GetInt(row, 5),
Actions = talentsData.GetEnumList<ActionType>(row, 6),
Conditions = new List<Condition>(),
Effects = new List<Effect>()
};
if (subRow)
{
talent = Talents[index];
talent.Conditions.Add(new Condition
{
Type = talentsData.GetEnum<ConditionType>( row, 7),
Value = talentsData.GetFloat(row, 8)
});
talent.Effects.Add(new Effect
{
Type = talentsData.GetEnum<EffectType>( row, 9),
Value = talentsData.GetFloat(row, 10)
});
}
return talent;
});
}
}
}
Explanation of
TalentsDatabase and SubRowsTalentsDatabase class is designed to handle a more complex data structure where some rows represent primary data (e.g., talent definitions) and others represent additional sub-data (e.g., conditions and effects associated with those talents). This is achieved using the EasyParser.ParseSubRowsData method, which is specifically tailored for handling sub-rows.
What are SubRows?
Row 0: "talent_1", "Fireball", 0.8, 10, 5, 50, "Attack", "", "", ""
Row 1: "", "", "", "", "", "", "", "Burn", 20, "Damage"
Row 2: "", "", "", "", "", "", "", "Slow", 10, "Movement"
Row 3: "talent_2", "Ice Blast", 0.7, 12, 6, 40, "Debuff", "", "", ""
Row 4: "", "", "", "", "", "", "", "Freeze", 15, "Movement"
talent_1).Conditions and Effects for talent_1.talent_2).talent_2.
How SubRows Work in
TalentsDatabaseEasyParser.ParseSubRowsData method processes data rows and dynamically determines whether a row is a main row (a new talent) or a sub-row (additional conditions and effects for an existing talent). Here’s how the logic works step-by-step:
Workflow
ParseSubRowsData method iterates through each row in talentsData.
if (subRow)
subRow flag is used to check if the current row is a sub-row:
Id) is empty or invalid, it is treated as a sub-row.
var talent = new Talent
{
Id = talentsData.GetString(row, 0),
Name = talentsData.GetString(row, 1),
Chance = talentsData.GetFloat(row, 2),
Cooldown = talentsData.GetFloat(row, 3),
Duration = talentsData.GetFloat(row, 4),
Cost = talentsData.GetInt(row, 5),
Actions = talentsData.GetEnumList<ActionType>(row, 6),
Conditions = new List<Condition>(),
Effects = new List<Effect>()
};
Talent object is created using the primary columns (e.g., Id, Name, Chance).Conditions and Effects lists are initialized as empty.Talent is added to the Talents list.
talent = Talents[index];
talent.Conditions.Add(new Condition
{
Type = talentsData.GetEnum<ConditionType>( row, 7),
Value = talentsData.GetFloat(row, 8)
});
talent.Effects.Add(new Effect
{
Type = talentsData.GetEnum<EffectType>( row, 9),
Value = talentsData.GetFloat(row, 10)
});
Talents[index]).Condition and Effect columns.Condition and Effect objects to the talent's respective lists.