The Project Starting State can be dowloaded on the project Github page :
https://github.com/Clean-Unity/CleanAchiever/releases
You can also download the final project on the repository.
It includes some resource modules that we won’t focus on in this tutorial, these are just Helpers that will give you some menu navigation capability, the game user interface, and a way to display some context information on screen with some popup.
The module we will focus on is the Objectives modules responsible of 5 main tasks :
– Fetching the game objectives from some database
– Flushing the objective set in order to generate a new one
– Stepping an active objective (increasing its progress by one unit)
– Claiming a completed objective reward
– Reset the objectives progress
An Objective can be fully described by the following fields :
/// <summary>
/// An Objective is defined by its status, description and progress.
/// We should fetch objectives per level.
/// </summary>
public struct ObjectivesModel
{
public int id;
public ObjectiveTypes type;
public string title;
public string description;
public bool isLocal; //can be used to detect if a countable objective must occur in one game or is a
general counter e.g.“Kill 10 ennemies in one game” or “Kill 10 ennemies”.
public int currentStep;
public int numberOfSteps;
public bool isRewardClaimed; //false by default, true when claim has been requested
public int reward;
}
Where the ObjectivesTypes are game specific (even if we can define some
general ones), here we will define :
/// <summary>
/// Types of Objectives.
/// </summary>
public enum ObjectiveTypes
{
// Countables
Scores,
Kills,
Hits,
Boss, PowerItems, Time,
// Special Events
Power,
Currency,
UnlockLevel,
UnlockCharacter,
Stats,
// Color Hits Events
Yellow, Green, Blue,
Other,
_COUNT }
To be as generic as possible, we will define Objective Sets (you can imagine having different objectives per level/world/game mode or whatever – this can also help you developing different implementations of the flushing process per
set):
public enum ObjectiveSet
{
Game,
World1, World2, World3, World4, World5
}
The Clean Unity Handbook
Finally we want our objective view to look like the following one (flush and reset buttons (inputs), stars to display completion status, title, description, progress and reward labels (outputs), and a claim button (I/O)) :
This leads to creating the following Objectives data structure :
public struct Objectives
{
public enum ObjectiveTypes
{
// Countables
Scores,
Kills,
Hits,
Boss,
PowerItems,
Time,
// Special Events
Power,
Currency,
UnlockLevel,
UnlockCharacter,
Stats,
// Color Hits Events
Yellow,
Green,
Blue,
Other,
_COUNT
public enum ObjectiveSet
{
Game,
World1, World2, World3, World4, World5
}
public struct ObjectivesModel
{
public int id;
public ObjectiveTypes type;
public string title;
public string description;
public bool isLocal;
public int currentStep;
public int numberOfSteps;
public bool isRewardClaimed;
//false by default, true when claim has been requested
}
[System.Serializable]
public struct ObjectivesViewModel
{
public Text titleLabel; public Text descriptionLabel; public Text completionLabel; public Text rewardLabel; public Button claimButton; public Image starImage;
} }
Note that the [System.Serializable] attribute allow the struct to be serialized (editable) in the Unity Editor. We need to assign our Objectives UI elements in a simple way.