Hello, I would like to create some design pattern with the right custom editor behaviour.
Below the design pattern (applied to a SpellBook example) :
using System.Collections.Generic;
[CreateAssetMenu(menuName = "MainClass")]
public class SpellBook : ScriptableObject
{
[SerializeField] List<Spell> spells;
}
public class Spell
{
[SerializeField] List<Effect> effects;
}
public abstract class Effect
{
[SerializeField] string effectName;
}
public class EffectA : Effect
{
[SerializeField] int specificIntField;
}
public class EffectB : Effect
{
[SerializeField] float specificFloatField;
}
What I want to do :
- Create the scriptable object from contextual menu (this is done thanks to CreateAssetMenu)
- Being able to add a spell to the spellbook (normal behaviour from Unity Editor)
- Being able to add an effect to the spell and either ideally chosing the type of effect I add when I click on the “+” button, either add a none-specific effect and afterwards through a field set the effect type*
- As soon as the element is created with the right type the specific field(s) from the effect should appear and be changeable (specificIntField or specificFloatField from above example).
*type, I did not create an enum or a effect-list somehow which I assume is needed for what I want. As it may be changing the answer and I do not have limitation on this, let me know what you would suggest.
Note : the spells and the effects have to be reorderable. The number of different effect classes is limited (less than 10). SpellBook has to be a ScriptableObject, Spell/Effect may be if needed ScriptableObjects.
I want to create a custom editor for those classes. I do not know on which class(es) I need to create the custom Editor(s) and/or PropertyDrawer(s).
I know this kind of design pattern is very common and this kind of question has been asked by the past but I am having a hard time finding the right approach even reading posts from the past (from this forum and other similar ones).
I hope everything is clear, do not hesitate if you need some more details
Thanks in advance