#Custom Editor

1 messages · Page 1 of 1 (latest)

steady hawk
#

Hello, So there is a class called 'Quest'. Now, I have another script call 'QuestGiver' that has a public list of type 'Quest'. Now i would like a custom unity Editor, where I would like to see only the int 'Required Amount' and 'Enemy ID' if I have chosen the 'Quest Type' as Kill(quest type is an enum)

Here are my scripts:

public class Quest
{
    public bool isActive;
    public int xpReward;

    public QuestType questType;
    public int requiredAmount;
    public int enemyID;

    private void Start() {
        if (questType == QuestType.Kill)
        {
            KillGoal killGoal = new KillGoal(requiredAmount, enemyID);
        }
    }
}
public enum QuestType
{
    Kill,
    Collect
}```

```public class QuestGiver : MonoBehaviour
{
    public List<Quest> quest;
    private QuestManager questManager;

    // Start is called before the first frame update
    void Start()
    {
        questManager = GameObject.FindGameObjectWithTag("QuestManager").GetComponent<QuestManager>();
        foreach (Quest questItem in quest)
        {
            questItem.isActive = true;
            questManager.AddQuests(questItem);
        }
    }
}```

Any help is really appreciated!!
storm mauve
#

The easiest way to achieve this, would be to make a CustomPropertyDrawer for your Quest type.

steady hawk
storm mauve
#

Property Drawers allow you to change how certain variables show up in the inspector. They can be tied to either types or attributes.
The benefit is, that you don't have to re-write the entire editor, but just make a property drawer for your Quest class. That will automatically alter the appearance of any Quest-type variable you display in the editor.