Class Reward
The state of a reward at runtime, managed by the IRewardManager.
Namespace: UnityEngine.GameFoundation
Syntax
public class Reward
Fields
claimTimestamps
For tracking any reward items that have been claimed in this cycle. The key is a reward item key, and the value is a timestamp of when it was successfully claimed. When the reward is reset, this collection is cleared.
Declaration
public Dictionary<string, long> claimTimestamps
Field Value
Type | Description |
---|---|
Dictionary<String, Int64> |
key
The unique key of the reward.
Declaration
public string key
Field Value
Type | Description |
---|---|
String |
rewardDefinition
The rewardDefinition on which this reward instance is based.
Declaration
public RewardDefinition rewardDefinition
Field Value
Type | Description |
---|---|
RewardDefinition |
Properties
countdownSeconds
Get the number of seconds until the next state change (can be negative). Either until the cooldown ends, or until the current claimable item expires.
Declaration
public float countdownSeconds { get; }
Property Value
Type | Description |
---|---|
Single |
countdownTicks
Gets the countdown in ticks. Ticks
Declaration
public long countdownTicks { get; }
Property Value
Type | Description |
---|---|
Int64 |
rewardItemStates
For every reward item, this collection will contain its RewardItemState. The only way to update this collection is by calling Update(Boolean).
Declaration
public Dictionary<string, RewardItemState> rewardItemStates { get; }
Property Value
Type | Description |
---|---|
Dictionary<String, RewardItemState> |
Methods
GetLastClaimableRewardItemKey()
Get the key of the reward item that is currently claimable. If multiple items are claimable, then this returns the one with the highest position (index) in the reward item collection.
Declaration
public string GetLastClaimableRewardItemKey()
Returns
Type | Description |
---|---|
String | Returns the key of a claimable reward item, or an empty string if none are claimable. |
IsInCooldown()
Tells whether this reward is in a cooldown state. This means we're waiting for a countdown until the next claimable item unlocks.
Declaration
public bool IsInCooldown()
Returns
Type | Description |
---|---|
Boolean | Returns true if this reward is in cooldown, otherwise false; |
Update(Boolean)
Checks to see if it's time to update state. If yes, this recalculates the state of each reward item in this reward instance. If the reward is reset, the rewardReset event is invoked. If any reward item states change, the rewardStateChanged event is invoked. Both events could be invoked in the same pass, but rewardReset would be invoked first.
Declaration
public void Update(bool force = false)
Parameters
Type | Name | Description |
---|---|---|
Boolean | force | If countdownTicks is more than 0, this method won't do anything. You can bypass the countdown gate by passing in true here. |
Events
rewardReset
Invoked when a Reward has been reset (all the claim timestamps were deleted).
Declaration
public static event Action<Reward> rewardReset
Event Type
Type | Description |
---|---|
Action<Reward> |
rewardStateChanged
Invoked when any of a Reward's item states have changed (including when a Reward is reset).
Declaration
public static event Action<Reward> rewardStateChanged
Event Type
Type | Description |
---|---|
Action<Reward> |