Databrain Documentation
databrain.ccDiscord
  • Welcome
  • Installation / Update
  • Interface
  • DataObject Property Drawer
    • No GUI Implemented - FIX
  • Getting started
  • Guides
    • Add data objects
    • Add data objects at runtime
    • Get initial data
    • Get/Set runtime data
    • Serialize DataObjects
    • Runtime Save & Load
    • Use custom serializer
    • Import
    • Search
    • Custom GUI
    • Custom GUI with Odin Inspector
    • Hierarchy Template
  • Separate DataObjects
  • Using Version Control
  • Attributes
    • DataObject attributes
    • Field attributes
  • API
    • DataLibrary
    • DataObject
  • FAQ
    • Databrain - FAQ
  • Add-ons
    • Events
    • Blackboard
    • Logic
      • Interface
      • Create Graph
      • Execute graph
      • Control flow execution in groups
      • Custom Nodes
        • Asynchronous execution
        • Node Attributes
      • Scene Components
      • Graph Events
      • Finite State Machine
        • Create custom Actions
        • Examples
        • State Machine Nodes
    • Stats
      • Achievements
      • Modifiers
      • Values
      • Progressions
      • Components
      • Nodes
    • Progress
      • Progress Settings
      • Progress Graph
      • Progress Resources
      • Runtime UI Setup
      • API
        • ProgressController
    • Techtree (LEGACY)
      • Techtree Manager
      • Techtree
      • TechtreeResource
      • Techtree UIBuilder
        • Custom Techtree Node Button
        • Tooltip
      • API
    • Localization
      • Localization Manager
      • Localization
      • Examples
      • Components
      • Import
      • API
    • Inventory
      • Getting started
      • Demo
      • Data setup
        • Inventories
        • Slot IDs
        • Items
          • Blueprints
          • Item rarities
        • Money
        • Loot tables
        • Events
      • Runtime UI
        • Setup
    • Dialogue
      • Getting Started
        • Demo
      • Dialogue runtime setup
      • Actors
        • Emotions
      • Localization
      • Audio
      • Animation
      • Variables
      • Custom theme
      • Import
      • Nodes
      • API
        • DialogueController
        • IDialogueUIControl
  • Changelog
    • Databrain - Changelog
      • 1.4.0
      • 1.3.2
      • 1.3.1
      • 1.3.0
      • 1.2.0
      • 1.1.0
      • 1.0.10
      • 1.0.9
      • 1.0.8
      • 1.0.7
      • <= 1.0.6
Powered by GitBook
On this page
  • API
  • Add achievement points
  • OnAchievementUnlocked
  • CurrentScore
  • IsUnlocked
  1. Add-ons
  2. Stats

Achievements

PreviousStatsNextModifiers

Last updated 2 years ago

using Databrain.Stats;

public class StatsAchievement : DataObject {}

The achievements data type lets you easily create unlockable achievements. Simply define the max score an achievement must reach to get unlocked. Use the following API to add points and listen to an unlocked event:

  1. Create a new achievement data object.

  2. Assign the total score and create a new OnAchievementUnlocked event.

Stats add-on comes with a dedicated StatsEvents type which contains either the unlcoked achievement, a new value or a new progression.

  1. OPTIONAL: If you have installed the Logic add-on, you can also add a custom logic which gets called on achievement unlocked.

API

Add achievement points

AddPoints(int _points);

public class AddAchievementPoints : MonoBehaviour    
{
    public DataLibrary data;
    
    [DataObjectDropdown("data")]
    public StatsAchievement achievement;
    
    public int points;

    // Directly add points to the achievement.
    // Do not worry about initial or runtime data. The points are automatically added
    // to the runtime data object
    public void AddPoints()
    {
        achievement.AddPoints(points);
    }
}

The points are automatically added to the runtime data object of the achievement data object.

OnAchievementUnlocked

Listen to the StatsEvents OnAchievementUnlocked

public class UIAchievement : MonoBehaviour
{
    public DataLibrary data;

    [DataObjectDropdown("data")]
    public StatsEvents OnAchievementUnlocked;
        
    public void Start()
    {
        data.OnDataInitialized += DataReady;
    }

    void DataReady()
    {
        // Register to the event
        OnAchievementUnlocked.RegisterListener(NewAchievement);
    } 
    
    // New achievement has been unlocked
    void NewAchievement(StatsEventData _data)
    {
        var _newAchievement = _data.newAchievement;
        Debug.Log("Achievement unlocked: " + _newAchievement.title);
    }

}

CurrentScore

Get the current score of the achievement

IsUnlocked

Get whether achievement is unlocked or not.

Optional, only if Logic add-on is installed