using NEG.Utils.Achievments.AchievmentTypes; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace NEG.Utils.Achievments { /// /// Static utility for achievment managment /// public static class Achievment { public static AchievmentManager Instance { get { if (instance == null) { instance = AchievmentManager.Builder.FromLabeledConfig(ConfigLabel) .WithLabeledBackend(BackendLabel) .Build(); } return instance; } } public static string BackendLabel { get => backendLabel; set { if(instance != null) { //Log + Quit helps debug builds Debug.LogError("Achievments - Cannot set backend label, Managed already created"); Application.Quit(1); } if (backendLabel != null) { //Log + Quit helps debug builds Debug.LogError("Multiple AchievmentBackends enabled, this is not allowed"); Application.Quit(1); } backendLabel = value; } } private static string backendLabel; /// /// You shouldn't have any reason to change this /// Used for tests. /// public static string ConfigLabel { private get => configLabel; set => configLabel = value; } /// /// You shouldn't have any reason to change this /// Used for tests. /// private static string configLabel = "Achivments"; private static AchievmentManager instance; #region Achievment Manipulation (Sets, Gets) /// /// Returns if an achivment at a given id is completed /// /// /// /// /// throws an if there is no achievment under id public static bool IsCompleted(string id) { return Instance.IsCompleted(id); } #region Toggle /// /// Sets a as completed.
///
/// /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static bool SetToggleAchivment(string id) { return Instance.SetToggleAchivment(id); } /// /// Gets a completion state from a .
///
/// /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static bool GetToggleState(string id) { return Instance.GetToggleState(id); } #endregion #region Int /// /// Sets progress of a given to
///
/// /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static bool SetIntProgress(string id, int progress) { return Instance.SetIntProgress(id, progress); } /// /// Changes progress of a given by
///
/// \ /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static bool ChangeIntProgress(string id, int delta) { return Instance.ChangeIntProgress(id, delta); } /// /// Gets current progress from a .
///
/// /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static int GetIntProgress(string id) { return Instance.GetIntProgress(id); } #endregion #region Float /// /// Sets progress of a given to
///
/// /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static bool SetFloatProgress(string id, float progress) { return Instance.SetFloatProgress(id, progress); } /// /// Changes progress of a given by
///
/// /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static bool ChangeFloatProgress(string id, float delta) { return Instance.ChangeFloatProgress(id, delta); } /// /// Gets current progress from a .
///
/// /// /// throws an if there is no achievment under id or an if achievment under id is of a different type public static float GetFloatProgress(string id) { return Instance.GetFloatProgress(id); } #endregion #endregion #region Test Api /// /// You shouldn't have any reason to use this
/// Use at your own risk, may cause unexpected behaviour
/// Used for tests ///
public static void NullifyInstance() { instance = null; } #endregion } }