@@ -15,18 +15,23 @@ public class SaveWindowEditor : OdinEditorWindow
1515 {
1616 private const string PlayerPrefsKey = "PlayerData" ;
1717 private const string JsonFileName = "player_data.json" ;
18+ private const string XmlFileName = "player_data.xml" ;
1819
1920 private string SavePath => Application . persistentDataPath ;
2021 private string JsonFilePath => Path . Combine ( SavePath , JsonFileName ) ;
22+ private string XmlFilePath => Path . Combine ( SavePath , XmlFileName ) ;
2123
2224 private Vector2 scrollPrefs ;
2325 private Vector2 scrollJson ;
26+ private Vector2 scrollXml ;
2427
2528 private string DecodedPrefsData ;
2629 private string DecodedJsonData ;
30+ private string DecodedXmlData ;
2731
2832 private string PrefsMessage = "❌ No PlayerPrefs data found." ;
2933 private string JsonMessage = "❌ No JSON file found." ;
34+ private string XmlMessage = "❌ No XML file found." ;
3035
3136 [ MenuItem ( "Tools/Save Window Editor" ) ]
3237 private static void OpenWindow ( )
@@ -37,25 +42,20 @@ private static void OpenWindow()
3742 window . Show ( ) ;
3843 }
3944
40- private void OnEnable ( )
41- {
42- Refresh ( ) ;
43- }
45+ private void OnEnable ( ) => Refresh ( ) ;
4446
4547 protected override void DrawEditor ( int index )
4648 {
47- DrawSection ( "🧠 PlayerPrefs Preview" , GetPlayerPrefsStoragePath ( ) , PrefsMessage , DecodedPrefsData , ref scrollPrefs ,
48- Refresh , DeletePlayerPrefs ) ;
49+ DrawSection ( "🧠 PlayerPrefs Preview" , GetPlayerPrefsPath ( ) , PrefsMessage , DecodedPrefsData , ref scrollPrefs , Refresh , DeletePlayerPrefs ) ;
50+ GUILayout . Space ( 20 ) ;
4951
52+ DrawSection ( "📄 JSON File Preview" , JsonFilePath , JsonMessage , DecodedJsonData , ref scrollJson , Refresh , DeleteJson ) ;
5053 GUILayout . Space ( 20 ) ;
5154
52- DrawSection ( "📄 JSON File Preview" , JsonFilePath , JsonMessage , DecodedJsonData , ref scrollJson ,
53- Refresh , DeleteJson ) ;
55+ DrawSection ( "📘 XML File Preview" , XmlFilePath , XmlMessage , DecodedXmlData , ref scrollXml , Refresh , DeleteXml ) ;
5456 }
5557
56- private void DrawSection ( string title , string path , string message , string data , ref Vector2 scrollPos ,
57- Action refreshAction ,
58- Action deleteAction )
58+ private void DrawSection ( string title , string path , string message , string data , ref Vector2 scrollPos , Action refreshAction , Action deleteAction )
5959 {
6060 SirenixEditorGUI . Title ( title , null , TextAlignment . Left , true ) ;
6161 SirenixEditorGUI . BeginBox ( ) ;
@@ -94,6 +94,7 @@ private void Refresh()
9494 {
9595 RefreshPlayerPrefs ( ) ;
9696 RefreshJsonFile ( ) ;
97+ RefreshXmlFile ( ) ;
9798 Repaint ( ) ;
9899 }
99100
@@ -108,9 +109,7 @@ private void RefreshPlayerPrefs()
108109 string base64 = PlayerPrefs . GetString ( PlayerPrefsKey ) ;
109110 byte [ ] data = Convert . FromBase64String ( base64 ) ;
110111 var deserialized = Sirenix . Serialization . SerializationUtility . DeserializeValue < PlayerData > ( data , DataFormat . JSON ) ;
111- string json = Encoding . UTF8 . GetString (
112- Sirenix . Serialization . SerializationUtility . SerializeValue ( deserialized , DataFormat . JSON )
113- ) ;
112+ string json = Encoding . UTF8 . GetString ( Sirenix . Serialization . SerializationUtility . SerializeValue ( deserialized , DataFormat . JSON ) ) ;
114113 DecodedPrefsData = json ;
115114 PrefsMessage = string . Empty ;
116115 }
@@ -149,6 +148,29 @@ private void RefreshJsonFile()
149148 }
150149 }
151150
151+ private void RefreshXmlFile ( )
152+ {
153+ DecodedXmlData = string . Empty ;
154+
155+ if ( File . Exists ( XmlFilePath ) )
156+ {
157+ try
158+ {
159+ DecodedXmlData = File . ReadAllText ( XmlFilePath ) ;
160+ XmlMessage = string . Empty ;
161+ }
162+ catch ( Exception e )
163+ {
164+ DecodedXmlData = $ "❌ Failed to read XML:\n { e . Message } ";
165+ XmlMessage = "❌ Failed to load XML file." ;
166+ }
167+ }
168+ else
169+ {
170+ XmlMessage = "❌ No XML file found." ;
171+ }
172+ }
173+
152174 private void DeletePlayerPrefs ( )
153175 {
154176 if ( PlayerPrefs . HasKey ( PlayerPrefsKey ) )
@@ -169,17 +191,27 @@ private void DeleteJson()
169191 Refresh ( ) ;
170192 }
171193 }
172-
173- private string GetPlayerPrefsStoragePath ( )
194+
195+ private void DeleteXml ( )
196+ {
197+ if ( File . Exists ( XmlFilePath ) )
198+ {
199+ File . Delete ( XmlFilePath ) ;
200+ Debug . Log ( "🧹 XML file deleted." ) ;
201+ Refresh ( ) ;
202+ }
203+ }
204+
205+ private string GetPlayerPrefsPath ( )
174206 {
175207#if UNITY_EDITOR_WIN
176208 return $@ "Windows Registry:\HKEY_CURRENT_USER\Software\Unity\UnityEditor\{ Application . companyName } \{ Application . productName } ";
177209#elif UNITY_EDITOR_OSX
178- return $ "~/Library/Preferences/unity.{ Application . companyName } .{ Application . productName } .plist";
210+ return $ "~/Library/Preferences/unity.{ Application . companyName } .{ Application . productName } .plist";
179211#else
180- return "📦 Platform not supported for PlayerPrefs path preview." ;
212+ return "📦 Platform not supported for PlayerPrefs path preview." ;
181213#endif
182214 }
183215 }
184216}
185- #endif
217+ #endif
0 commit comments