Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit bf2d329

Browse files
committed
feat: СОХРАНЕНИЕ и ЗАГРУЗКА!
1 parent d57d17d commit bf2d329

File tree

9 files changed

+77
-9
lines changed

9 files changed

+77
-9
lines changed

Assets/AddressableAssetsData/AddressableAssetSettings.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ MonoBehaviour:
2525
m_GroupAssets:
2626
- {fileID: 11400000, guid: f0364c80bdd4e0648af018bca9793a3f, type: 2}
2727
- {fileID: 11400000, guid: d3e743121d5fc7442a1e4d4b7a9459cd, type: 2}
28+
- {fileID: 11400000, guid: 6da666d6e152bbe49a39f368bf1b1e7e, type: 2}
2829
m_BuildSettings:
2930
m_CompileScriptsInVirtualMode: 0
3031
m_CleanupStreamingAssetsAfterBuilds: 1
Binary file not shown.

Packages/com.nuclearband.sodatabase/Runtime/DataNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.Reflection;
2+
using Newtonsoft.Json;
23
using Sirenix.OdinInspector;
34

45
namespace NuclearBand
56
{
7+
[JsonObject(MemberSerialization.OptIn)]
68
public class DataNode : SerializedScriptableObject
79
{
810
protected virtual void OnEnable()

Packages/com.nuclearband.sodatabase/Runtime/Holders/FolderHolder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ protected override void Remove()
5252
SODatabaseInternal.RemoveFolder(Path + "/" + Name);
5353
}
5454
#endif
55-
5655
}
5756
}

Packages/com.nuclearband.sodatabase/Runtime/Holders/Holder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using Newtonsoft.Json;
12
using Sirenix.OdinInspector;
23
using UnityEngine;
34

45
namespace NuclearBand
56
{
7+
[JsonObject(MemberSerialization.OptIn)]
68
public abstract class Holder
79
{
810
public Holder()

Packages/com.nuclearband.sodatabase/Runtime/SODatabase.cs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Threading.Tasks;
8+
using JetBrains.Annotations;
9+
using Newtonsoft.Json;
10+
using Sirenix.Utilities;
811
using UnityEngine;
912
using UnityEngine.AddressableAssets;
1013

@@ -13,6 +16,7 @@ namespace NuclearBand
1316
public static class SODatabase
1417
{
1518
private static FolderHolder root;
19+
private static Dictionary<string, string> dataNodeJSONs;
1620

1721
public static async Task Init(Action<float> onProgress, Action onComplete)
1822
{
@@ -75,15 +79,60 @@ public static List<T> GetModels<T>(string path) where T : DataNode
7579
return curFolder.DataNodes.Values.OfType<T>().ToList();
7680
}
7781

78-
public static string Save()
82+
public static void Save()
7983
{
80-
81-
return "";
84+
var res = SaveFolderHolder(root, "");
85+
foreach (var pair in res)
86+
PlayerPrefs.SetString(pair.Key, pair.Value);
87+
PlayerPrefs.Save();
88+
}
89+
90+
static Dictionary<string, string> SaveFolderHolder(FolderHolder folderHolder, string path)
91+
{
92+
var res = new Dictionary<string, string>();
93+
foreach (var dataNodePair in folderHolder.DataNodes)
94+
{
95+
var fullPath = dataNodePair.Key;
96+
if (!string.IsNullOrEmpty(path))
97+
fullPath = path + '/' + fullPath;
98+
var json = JsonConvert.SerializeObject(dataNodePair.Value);
99+
res.Add(fullPath, json);
100+
}
101+
102+
foreach (var folderHolderPair in folderHolder.FolderHolders)
103+
{
104+
var fullPath = folderHolderPair.Key;
105+
if (!string.IsNullOrEmpty(path))
106+
fullPath = path + '/' + fullPath;
107+
var resAdd = SaveFolderHolder(folderHolderPair.Value, fullPath);
108+
resAdd.ForEach(x => res.Add(x.Key, x.Value));
109+
}
110+
return res;
82111
}
83112

84113
public static void Load()
85114
{
86-
115+
LoadFolderHolder(root, "");
116+
}
117+
118+
static void LoadFolderHolder(FolderHolder folderHolder, string path)
119+
{
120+
foreach (var dataNodePair in folderHolder.DataNodes)
121+
{
122+
var fullPath = dataNodePair.Key;
123+
if (!string.IsNullOrEmpty(path))
124+
fullPath = path + '/' + fullPath;
125+
var json = PlayerPrefs.GetString(fullPath);
126+
JsonConvert.PopulateObject(json, dataNodePair.Value);
127+
}
128+
129+
foreach (var folderHolderPair in folderHolder.FolderHolders)
130+
{
131+
var fullPath = folderHolderPair.Key;
132+
if (!string.IsNullOrEmpty(path))
133+
fullPath = path + '/' + fullPath;
134+
LoadFolderHolder(folderHolderPair.Value, fullPath);
135+
}
87136
}
88137
}
89138
}

Packages/com.nuclearband.sodatabase/Samples/Sample/Example1Scene.unity

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ GameObject:
136136
- component: {fileID: 396960463}
137137
- component: {fileID: 396960466}
138138
- component: {fileID: 396960467}
139+
- component: {fileID: 396960468}
139140
m_Layer: 0
140141
m_Name: Main Camera
141142
m_TagString: MainCamera
@@ -232,3 +233,15 @@ MonoBehaviour:
232233
m_Script: {fileID: 11500000, guid: d73ee2b3c89d77e40a3cf6bc38cc79be, type: 3}
233234
m_Name:
234235
m_EditorClassIdentifier:
236+
--- !u!114 &396960468
237+
MonoBehaviour:
238+
m_ObjectHideFlags: 0
239+
m_CorrespondingSourceObject: {fileID: 0}
240+
m_PrefabInstance: {fileID: 0}
241+
m_PrefabAsset: {fileID: 0}
242+
m_GameObject: {fileID: 396960462}
243+
m_Enabled: 1
244+
m_EditorHideFlags: 0
245+
m_Script: {fileID: 11500000, guid: 812aa3b1e0c34c9e9645e50d1b1ab38c, type: 3}
246+
m_Name:
247+
m_EditorClassIdentifier:

Packages/com.nuclearband.sodatabase/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "com.nuclearband.sodatabase",
3-
"displayName": "Scriptable Objeсt database",
3+
"displayName": "Scriptable Obje\u0441t database",
44
"version": "1.5.3",
55
"dependencies": {
6-
"com.unity.addressables": "1.7.5"
6+
"com.unity.addressables": "1.7.5",
7+
"com.unity.nuget.newtonsoft-json": "2.0.0"
78
},
89
"author": {
910
"name": "Tr0sT",
@@ -26,4 +27,4 @@
2627
}
2728
],
2829
"type": "library"
29-
}
30+
}

Packages/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"com.unity.2d.tilemap": "1.0.0",
99
"com.unity.addressables": "1.9.2",
1010
"com.unity.ide.rider": "2.0.5",
11-
"com.unity.ide.visualstudio": "2.0.1",
11+
"com.unity.ide.visualstudio": "2.0.2",
1212
"com.unity.ide.vscode": "1.2.1",
13+
"com.unity.nuget.newtonsoft-json": "2.0.0",
1314
"com.unity.test-framework": "1.1.14",
1415
"com.unity.textmeshpro": "3.0.0-preview.14",
1516
"com.unity.timeline": "1.4.0",

0 commit comments

Comments
 (0)