@@ -64,75 +64,41 @@ public abstract class Saveable : Registerable, ISaveable
64
64
65
65
## Usage Examples
66
66
67
- ### Basic Save/Load Implementation
67
+ ### Using SaveableField in Quests and NPCs
68
+
69
+ The SaveableField attribute works with Quest and NPC classes, automatically handling the saving and loading of marked fields:
68
70
69
71
``` csharp
70
- // Create a class that extends Saveable
71
- public class MyModData : Saveable
72
+ // Define a custom data class for your save data
73
+ public class OrderData
72
74
{
73
- // Mark fields to be saved with the SaveableField attribute
74
- [SaveableField (" playerStats" )]
75
- private PlayerStats _playerStats = new PlayerStats ();
76
-
77
- [SaveableField (" unlockedItems" )]
78
- private List <string > _unlockedItems = new List <string >();
79
-
80
- // Optional: Override callbacks
81
- public override void OnSaved ()
82
- {
83
- Console .WriteLine (" Data has been saved!" );
84
- }
85
-
86
- public override void OnLoaded ()
87
- {
88
- Console .WriteLine ($" Loaded {_unlockedItems .Count } unlocked items" );
89
- RefreshUI ();
90
- }
75
+ public ProductDefinition ? Product ;
76
+ public int Amount ;
77
+ public int Price ;
91
78
}
92
- ```
93
79
94
- ### Handling Complex Objects
95
-
96
- ``` csharp
97
- public class ModConfig : Saveable
80
+ // Use it in your Quest class
81
+ public class MyFancyQuest : Quest
98
82
{
99
- [SaveableField (" settings" )]
100
- private Dictionary <string , object > _settings = new Dictionary <string , object >();
101
-
102
- [SaveableField (" playerProgress" )]
103
- private PlayerProgress _playerProgress = new PlayerProgress ();
104
-
105
- // Provide helper methods to work with your data
106
- public T GetSetting <T >(string key , T defaultValue = default )
83
+ // Mark the field to be automatically saved with the SaveableField attribute
84
+ [SaveableField (" Order" )]
85
+ private OrderData _orderData = new OrderData ();
86
+
87
+ public void SetOrderAmount (int amount )
107
88
{
108
- if (_settings .TryGetValue (key , out var value ) && value is T typedValue )
109
- return typedValue ;
110
- return defaultValue ;
89
+ _orderData .Amount = amount ;
111
90
}
112
91
113
- public void SetSetting < T >( string key , T value )
92
+ public void SetOrderProduct ( ProductDefinition product )
114
93
{
115
- _settings [ key ] = value ;
94
+ _orderData . Product = product ;
116
95
}
117
- }
118
- ```
119
-
120
- ### Cross-compatibility Support
121
-
122
- The save system is designed to work consistently across both Mono and Il2Cpp builds:
123
-
124
- ``` csharp
125
- // This code works the same way in both Mono and Il2Cpp builds
126
- public class MyQuestData : Saveable
127
- {
128
- [SaveableField (" questProgress" )]
129
- private Dictionary <string , int > _questProgress = new Dictionary <string , int >();
130
96
131
- // Method to update quest progress
132
- public void UpdateQuestProgress (string questId , int progress )
97
+ public void SetOrderPrice (int price )
133
98
{
134
- _questProgress [questId ] = progress ;
135
- // Data will be automatically saved through the Saveable system
99
+ _orderData .Price = price ;
136
100
}
137
101
}
138
- ```
102
+ ```
103
+
104
+ The SaveableField attribute is recognized during the save/load process for NPC and Quest objects, and the data is automatically persisted within the current save file.
0 commit comments