Iuvo Unity 0.5.1
This is library containing a variety of helper classes and extension methods for the Unity gane engine.
GitHub | Iuvo Unity Updates | Creator
Loading...
Searching...
No Matches
IuvoUnity.Configurations.LevelConfiguration Class Reference
Inheritance diagram for IuvoUnity.Configurations.LevelConfiguration:
IuvoUnity.Configurations.BaseConfig< T > IuvoUnity.Interfaces.IConfigure< T > IuvoUnity.Interfaces.IReconfigure< T > IuvoUnity.BaseClasses.IuvoInterfaceBase IuvoUnity.BaseClasses.IuvoInterfaceBase

Public Member Functions

AnimationCurve GetDefaultExperienceCurve ()
virtual void OnEnable ()
virtual void OnDisable ()
void Serialize (LevelComponentData levelComponent)
LevelComponentDataDeserializeLevelComponent ()
int GetExpAtLevel (int level)
int GetExperienceToNextLevel (int currLevel, int cumulativeExp)
 Returns EXP still required to reach the next level from the current state. Uses cumulative EXP values stored in the exp curve.
void SetLevelScalingCurve (AnimationCurve newExpCurve)
 Sets a new experience curve for level scaling.
Dictionary< int, int > GetFullLevelTable ()
 Returns a dictionary mapping each level to the cumulative EXP required to reach that level.
override void PrintInfo ()
 Prints detailed information about the level configuration, including the EXP curve and last known level component data.
Public Member Functions inherited from IuvoUnity.Configurations.BaseConfig< T >
virtual void Configure (T configurable)
virtual void Reconfigure (T reconfigurable)
virtual string GetConfigSerializePath (string actingConfigClass, string objectToSerializeName, string parentConfigClass="BaseConfig")

Public Attributes

string savedItemName = "LevelComponent"
Public Attributes inherited from IuvoUnity.Configurations.BaseConfig< T >
string configName

Protected Member Functions

virtual void ImplementDefaultScalingAlgorithm ()

Properties

int MaxLevel [get]

Private Attributes

AnimationCurve DefaultLevelingCurve
AnimationCurve expCurve
LevelComponentData lastLevelComponentData = new LevelComponentData { CurrentLevel = -1 }

Member Function Documentation

◆ DeserializeLevelComponent()

LevelComponentData? IuvoUnity.Configurations.LevelConfiguration.DeserializeLevelComponent ( )
67 {
68 string filePath = GetConfigSerializePath("LevelConfiguration", savedItemName, "BaseConfig");
69 if (!System.IO.File.Exists(filePath))
70 {
71 IuvoDebug.DebugLogWarning($"No save file found at {filePath}");
72 return null;
73 }
74
75 string json = System.IO.File.ReadAllText(filePath);
76 LevelComponentData data = JsonUtility.FromJson<LevelComponentData>(json);
77 lastLevelComponentData = data;
78 return data;
79 }

References IuvoUnity.Debug.IuvoDebug.DebugLogWarning(), IuvoUnity.Configurations.BaseConfig< T >.GetConfigSerializePath(), lastLevelComponentData, and savedItemName.

◆ GetDefaultExperienceCurve()

AnimationCurve IuvoUnity.Configurations.LevelConfiguration.GetDefaultExperienceCurve ( )
24 {
25 return DefaultLevelingCurve;
26 }

References DefaultLevelingCurve.

Referenced by ImplementDefaultScalingAlgorithm().

◆ GetExpAtLevel()

int IuvoUnity.Configurations.LevelConfiguration.GetExpAtLevel ( int level)
86 {
87 if (level < 1 || level > MaxLevel)
88 {
89 IuvoDebug.DebugLogWarning("Level out of range. Returning 0.");
90 return 0;
91 }
92 float exp = expCurve.Evaluate(level);
93 return Mathf.RoundToInt(exp);
94 }

References IuvoUnity.Debug.IuvoDebug.DebugLogWarning(), expCurve, and MaxLevel.

Referenced by IuvoUnity.BaseClasses.LevelComponent.CheckLevelUp(), GetExperienceToNextLevel(), and GetFullLevelTable().

◆ GetExperienceToNextLevel()

int IuvoUnity.Configurations.LevelConfiguration.GetExperienceToNextLevel ( int currLevel,
int cumulativeExp )

Returns EXP still required to reach the next level from the current state. Uses cumulative EXP values stored in the exp curve.

101 {
102 if (currLevel < 1 || currLevel >= MaxLevel)
103 {
104 return 0;
105 }
106
107 int nextLevelExp = GetExpAtLevel(currLevel + 1);
108 return Mathf.Max(0, nextLevelExp - cumulativeExp);
109 }

References GetExpAtLevel(), and MaxLevel.

◆ GetFullLevelTable()

Dictionary< int, int > IuvoUnity.Configurations.LevelConfiguration.GetFullLevelTable ( )

Returns a dictionary mapping each level to the cumulative EXP required to reach that level.

Returns
140 {
141 Dictionary<int, int> levelTable = new Dictionary<int, int>();
142 for (int level = 1; level <= MaxLevel; level++)
143 {
144 levelTable[level] = GetExpAtLevel(level);
145 }
146 return levelTable;
147 }

References GetExpAtLevel(), and MaxLevel.

Referenced by PrintInfo().

◆ ImplementDefaultScalingAlgorithm()

virtual void IuvoUnity.Configurations.LevelConfiguration.ImplementDefaultScalingAlgorithm ( )
protectedvirtual
128 {
129 IuvoDebug.DebugLog("Implementing default exp curve...");
130
131 expCurve = new AnimationCurve(GetDefaultExperienceCurve().keys);
132 }

References IuvoUnity.Debug.IuvoDebug.DebugLog(), expCurve, and GetDefaultExperienceCurve().

Referenced by OnEnable(), and SetLevelScalingCurve().

◆ OnDisable()

virtual void IuvoUnity.Configurations.LevelConfiguration.OnDisable ( )
virtual
47 {
48 IuvoDebug.DebugLog("LevelConfiguration disabled.");
49 }

References IuvoUnity.Debug.IuvoDebug.DebugLog().

◆ OnEnable()

virtual void IuvoUnity.Configurations.LevelConfiguration.OnEnable ( )
virtual
37 {
38 configName = typeof(LevelConfiguration).ToString();
39
40 if (expCurve == null)
41 {
42 ImplementDefaultScalingAlgorithm();
43 }
44 }

References IuvoUnity.Configurations.BaseConfig< T >.configName, expCurve, and ImplementDefaultScalingAlgorithm().

◆ PrintInfo()

override void IuvoUnity.Configurations.LevelConfiguration.PrintInfo ( )
virtual

Prints detailed information about the level configuration, including the EXP curve and last known level component data.

Reimplemented from IuvoUnity.Configurations.BaseConfig< T >.

156 {
157 base.PrintInfo();
158
159 IuvoDebug.DebugLog("Level EXP Curve:");
160 Dictionary<int, int> scaling = GetFullLevelTable();
161 foreach (var kvp in scaling)
162 {
163 IuvoDebug.DebugLog($" Level {kvp.Key}: {kvp.Value} EXP");
164 }
165
166 if (lastLevelComponentData.IsValid())
167 {
168 IuvoDebug.DebugLog("Last Level Component:");
169 IuvoDebug.DebugLog($" Is Max Level: {lastLevelComponentData.CurrentLevel >= MaxLevel}");
170 IuvoDebug.DebugLog($" Level: {lastLevelComponentData.CurrentLevel}");
171 IuvoDebug.DebugLog($" Experience: {lastLevelComponentData.LevelProgressExperience}");
172 IuvoDebug.DebugLog($" Lifetime Experience: {lastLevelComponentData.LifetimeExperience}");
173
174 IuvoDebug.DebugLog($" Experience to Next Level: {lastLevelComponentData.ExperienceUntilNextLevel}");
175 IuvoDebug.DebugLog($" Next Level EXP Requirement: {lastLevelComponentData.NextLevelExperienceMinimum}");
176
177 IuvoDebug.DebugLog($" Current LevelUp Points: {lastLevelComponentData.CurrentLevelUpPoints}");
178 IuvoDebug.DebugLog($" Max LevelUp Points: {lastLevelComponentData.MaxLevelUpPoints}");
179 }
180 }

References IuvoUnity.Debug.IuvoDebug.DebugLog(), GetFullLevelTable(), and lastLevelComponentData.

◆ Serialize()

void IuvoUnity.Configurations.LevelConfiguration.Serialize ( LevelComponentData levelComponent)
54 {
55 string json = JsonUtility.ToJson(levelComponent);
56 string filePath = GetConfigSerializePath("LevelConfiguration", savedItemName, "BaseConfig");
57 if (filePath == "")
58 {
59 IuvoDebug.DebugLogError("Failed to get file path for serialization.");
60 return;
61 }
62 System.IO.File.WriteAllText(filePath, json);
63 IuvoDebug.DebugLog($"Serialized LevelComponent to {filePath}");
64 }

References IuvoUnity.Debug.IuvoDebug.DebugLog(), IuvoUnity.Debug.IuvoDebug.DebugLogError(), IuvoUnity.Configurations.BaseConfig< T >.GetConfigSerializePath(), and savedItemName.

◆ SetLevelScalingCurve()

void IuvoUnity.Configurations.LevelConfiguration.SetLevelScalingCurve ( AnimationCurve newExpCurve)

Sets a new experience curve for level scaling.

Parameters
newExpCurve
116 {
117 if (newExpCurve == null)
118 {
119 IuvoDebug.DebugLogError("New Expereience curve cannot be null. Implementing default scaling");
120 ImplementDefaultScalingAlgorithm();
121 return;
122 }
123 IuvoDebug.DebugLog("Setting level scaling algorithm...");
124 expCurve = newExpCurve;
125 }

References IuvoUnity.Debug.IuvoDebug.DebugLog(), IuvoUnity.Debug.IuvoDebug.DebugLogError(), expCurve, and ImplementDefaultScalingAlgorithm().

Member Data Documentation

◆ DefaultLevelingCurve

AnimationCurve IuvoUnity.Configurations.LevelConfiguration.DefaultLevelingCurve
private
Initial value:
= new AnimationCurve(
new Keyframe(1, 100),
new Keyframe(25, 25000),
new Keyframe(50, 150000),
new Keyframe(75, 2500000),
new Keyframe(100, 50000000)
)

Referenced by GetDefaultExperienceCurve().

◆ expCurve

AnimationCurve IuvoUnity.Configurations.LevelConfiguration.expCurve
private

◆ lastLevelComponentData

LevelComponentData IuvoUnity.Configurations.LevelConfiguration.lastLevelComponentData = new LevelComponentData { CurrentLevel = -1 }
private
34{ CurrentLevel = -1 };

Referenced by DeserializeLevelComponent(), and PrintInfo().

◆ savedItemName

string IuvoUnity.Configurations.LevelConfiguration.savedItemName = "LevelComponent"

Property Documentation

◆ MaxLevel

int IuvoUnity.Configurations.LevelConfiguration.MaxLevel
get

The documentation for this class was generated from the following file: