Back and a bit defeated. Although I managed to get the editor to show off abilities and have the drop down work similarly to how the items work from the PropertyDrawer.
I wanted to be able to see my skills in the editor so I just copy pasted and switched out some things that you did for the InventoryItem and made a new section under ‘HasSkill’ by re-using your OnGUI code and DrawInventoryItemList() method. Although it would be cool to have the functionality of the slider with the chosen skill that way it kills two birds with one stone.
But I’m unsure how to set that part up. Anyways here’s the screenshot of the editor skill working.
Inside OnGUI from your PredicatePropertyDrawer I just followed what you did with the items aforementioned.
private Dictionary<string, Skill> skills;
if (selectedPredicate == EPredicate.HasSkill)
{
position.y += propHeight;
DrawAbilityList(position, parameterZero);
}
void DrawAbilityList(Rect position, SerializedProperty element)
{
BuildAbilityList();
List<string> ids = skills.Keys.ToList();
List<string> displayNames = new List<string>();
foreach (string id in ids)
{
displayNames.Add(skills[id].GetDisplayName());
}
int index = ids.IndexOf(element.stringValue);
EditorGUI.BeginProperty(position, new GUIContent("Skills"), element);
int newIndex = EditorGUI.Popup(position, "Skill Required:", index, displayNames.ToArray());
if (newIndex != index)
{
element.stringValue = ids[newIndex];
}
}
void BuildAbilityList()
{
if (skills != null) return;
skills = new Dictionary<string, Skill>();
foreach (Skill skill in Resources.LoadAll<Skill>(""))
{
skills[skill.GetItemID()] = skill;
}
}
I’m no way near the level of comprehending all of this, but it does work inside the Inspector as I showed you and it’s mostly re-using your code so it should be OKAY hopefully. Feel free to lecture me if what I’m doing is idiotic haha.
Okay so this is all I’ve been able to do… I implemented the interface into SkillTree and set up a property / serializefield for condition on the Skill class itself. (As shown on the image)
I have implemented the Evaluate member but at this point I’m not entirely sure how to do a proper check because with the way it works it just unlocks any skill regardless if I’m negating it or don’t have any skill unlocked.
Anyways here is the code so far… (not much because this part still isn’t quite there yet for me to fulfill on my own.)
Skilltree.cs
public void CanBeUnlocked(int id_skill)
{
if (skillsDictionary.TryGetValue(id_skill, out inspectedSkill))
{
IsSkillUnlocked(id_skill);
}
}
public bool IsSkillUnlocked(int id_skill)
{
return inspectedSkill.Condition.Check(GetComponents<IPredicateEvaluator>());
}
public bool? Evaluate(EPredicate predicate, List<string> parameters)
{
if (predicate == EPredicate.HasSkill)
{
if (inspectedSkill.RequiredPointsToUnlock <= availablePoints)
{
UnlockSkill(inspectedSkill.SkillID);
}
}
return null;
}
The only difference is I’m no longer checking for any Dependencies. UnlockSkill() is still the same from the first post so really there’s just one less check I’m going through to unlock a skill currently.