Skip to content

Commit aa25c3a

Browse files
committed
feat: completed tools for players prefs
1 parent 7592940 commit aa25c3a

File tree

5 files changed

+339
-129
lines changed

5 files changed

+339
-129
lines changed

Assets/Code/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#if UNITY_EDITOR
2+
using System;
3+
using Sirenix.OdinInspector.Editor;
4+
using Sirenix.Serialization;
5+
using Sirenix.Utilities.Editor;
6+
using UnityEditor;
7+
using UnityEngine;
8+
using SerializationUtility = Sirenix.Serialization.SerializationUtility;
9+
10+
namespace Code.Editor
11+
{
12+
public class SaveWindowEditor : OdinEditorWindow
13+
{
14+
private const string PlayerDataKey = "PlayerData";
15+
16+
private string savePath => Application.persistentDataPath;
17+
private Vector2 scrollPos;
18+
19+
[MenuItem("Tools/Save Window Editor")]
20+
private static void OpenWindow()
21+
{
22+
var window = GetWindow<SaveWindowEditor>();
23+
window.titleContent = new GUIContent("Save Window Editor");
24+
window.minSize = new Vector2(500, 600);
25+
window.Show();
26+
}
27+
28+
public string DecodedPlayerData;
29+
public string Message = "❌ No PlayerData found.";
30+
31+
private void OnEnable()
32+
{
33+
Refresh();
34+
}
35+
36+
protected override void DrawEditor(int index)
37+
{
38+
EditorGUILayout.Space();
39+
40+
// Main Box Group
41+
SirenixEditorGUI.Title("🧠 PlayerPrefs Preview", null, TextAlignment.Left, true);
42+
SirenixEditorGUI.BeginBox();
43+
44+
EditorGUILayout.LabelField("📁 Save Location", EditorStyles.boldLabel);
45+
EditorGUILayout.HelpBox(savePath, MessageType.Info);
46+
47+
EditorGUILayout.Space();
48+
49+
if (!string.IsNullOrEmpty(DecodedPlayerData))
50+
{
51+
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(300));
52+
EditorGUILayout.TextArea(DecodedPlayerData, GUILayout.ExpandHeight(true));
53+
EditorGUILayout.EndScrollView();
54+
}
55+
else
56+
{
57+
EditorGUILayout.HelpBox(Message, MessageType.Warning);
58+
}
59+
60+
GUILayout.Space(10);
61+
62+
// Buttons
63+
GUI.backgroundColor = new Color(0.6f, 0.9f, 1f); // голубая
64+
if (GUILayout.Button("🔄 Refresh", GUILayout.Height(35)))
65+
Refresh();
66+
67+
GUILayout.Space(5);
68+
69+
GUI.backgroundColor = new Color(1f, 0.4f, 0.4f); // красная
70+
if (GUILayout.Button("🗑 Delete PlayerData", GUILayout.Height(35)))
71+
DeletePlayerData();
72+
73+
GUI.backgroundColor = Color.white;
74+
75+
SirenixEditorGUI.EndBox();
76+
}
77+
78+
private void Refresh()
79+
{
80+
DecodedPlayerData = string.Empty;
81+
82+
if (PlayerPrefs.HasKey(PlayerDataKey))
83+
{
84+
try
85+
{
86+
string base64 = PlayerPrefs.GetString(PlayerDataKey);
87+
byte[] data = Convert.FromBase64String(base64);
88+
object deserialized = SerializationUtility.DeserializeValue<object>(data, DataFormat.JSON);
89+
DecodedPlayerData = JsonUtility.ToJson(deserialized, true);
90+
Message = string.Empty;
91+
}
92+
catch (Exception e)
93+
{
94+
DecodedPlayerData = $"❌ Failed to decode PlayerData:\n{e.Message}";
95+
}
96+
}
97+
else
98+
{
99+
Message = "❌ No PlayerData found.";
100+
}
101+
102+
Repaint();
103+
}
104+
105+
private void DeletePlayerData()
106+
{
107+
if (PlayerPrefs.HasKey(PlayerDataKey))
108+
{
109+
PlayerPrefs.DeleteKey(PlayerDataKey);
110+
PlayerPrefs.Save();
111+
Refresh();
112+
Debug.Log("🧹 PlayerData deleted.");
113+
}
114+
}
115+
}
116+
}
117+
#endif

Assets/Code/Editor/SaveWindowEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ProjectSettings/ProjectSettings.asset

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ PlayerSettings:
833833
webGLMemoryGeometricGrowthStep: 0.2
834834
webGLMemoryGeometricGrowthCap: 96
835835
webGLPowerPreference: 2
836-
scriptingDefineSymbols: {}
836+
scriptingDefineSymbols:
837+
Standalone: ODIN_INSPECTOR;ODIN_INSPECTOR_3;ODIN_INSPECTOR_3_1
837838
additionalCompilerArguments: {}
838839
platformArchitecture: {}
839840
scriptingBackend: {}

0 commit comments

Comments
 (0)