Create a Custom Quest Reward

v4.0

Often your game will have unique mechanics, and you may wish to include those as rewards.

Read on to learn more about the anatomy of a Quest Reward Inspector, or visit the pages below to create the required scripts, and then code your first custom Quest Reward.

pageYour Quest RewardpageYour Quest Reward EditorpageYour Quest Reward Drawer

Anatomy of a Quest Reward Inspector

Each Quest Reward may have a different inspector. I've created custom Inspectors for each of the Quest Rewards that ship with Game Modules, however custom Inspectors are not required -- they're just a convenience and look prettier.

We will be looking at the PointReward reward.

This is a "PointReward" QuestReward, which I've named "300 Experience". The top portion is the custom Inspector, while the bottom portion is the default Inspector. Both accomplish the same thing, and have the same fields exposed.

If you create custom Quest Rewards, you can create custom Inspectors, or not -- entirely up to you. If you do choose to create custom Inspectors, you can follow the same pattern explained here.

There are three scripts that make up a fully formed Quest Reward which can be viewed in the Editor with a custom Inspector. See full details about creating your own on the pages nexted in this section.

Class which inherits from QuestReward

The PointReward class inherits from QuestReward. This is the class which performs the actual reward code. The derived class is required to have their own version of GiveReward().

// Each derived class is required to have this method
public abstract void GiveReward(IUseGameModules owner);

Editor Class

The PointRewardEditor class inherits from QuestRewardEditor, and is the script which tells Unity to draw a custom Inspector when the PointReward object is being viewed.

It overrides the CreateDrawer() method, and nothing else. While it does not seem like much, it is required for displaying the custom Inspector.

protected override QuestRewardDrawer CreateDrawer()
{
    questRewardDrawer = ScriptableObject.CreateInstance<PointRewardDrawer>();
    return questRewardDrawer;
}

Drawer Class

Finally the PointRewardDrawer class inherits from QuestRewardDrawer. This is the class which does the actual drawing of the custom Inspector.

This is using the static class InfinityPBR.InfinityEditor, which you can also use to make your own custom Inspectors.

public override bool CanHandle(QuestReward questReward) 
    => questReward is PointReward;

protected override void ShowSpecificData(QuestReward questReward) 
    => ShowDataForPointReward(questReward as PointReward);
       
private void ShowDataForPointReward(PointReward questReward)
{
    // Draw Stuff
}

Last updated