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

Commit aea0dc4

Browse files
committed
feat: SODatabaseInternals
1 parent 9129d46 commit aea0dc4

File tree

6 files changed

+62
-8
lines changed

6 files changed

+62
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ obj/*
1313
.gradle/*
1414
*.aab
1515
Logs/*
16-
Assets/Plugins/Sirenix*
16+
Assets/*

Packages/com.nuclearband.sodatabase/Editor/ScriptableObjectDatabaseEditorWindow.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ private static void Open()
1919
{
2020
var window = GetWindow<ScriptableObjectDatabaseEditorWindow>();
2121
window.position = GUIHelper.GetEditorWindowRect().AlignCenter(800, 500);
22+
window.OnClose += () =>
23+
{
24+
AssetDatabase.SaveAssets();
25+
AssetDatabase.Refresh();
26+
};
2227
}
2328

2429
protected override OdinMenuTree BuildMenuTree()
@@ -59,7 +64,7 @@ private void SelectionChanged(SelectionChangedType obj)
5964
throw new ArgumentOutOfRangeException(nameof(obj), obj, null);
6065
}
6166
}
62-
67+
6368
void AddAllAssetsAtPath(
6469
OdinMenuTree tree,
6570
string assetFolderPath,

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,5 @@ public static List<T> GetModels<T>(string path) where T : DataNode
7474

7575
return curFolder.DataNodes.Values.OfType<T>().ToList();
7676
}
77-
78-
#if UNITY_EDITOR
79-
public static T GetModelForEdit<T>(string path) where T : DataNode => AssetDatabase.LoadAssetAtPath(SODatabaseSettings.Path + path + ".asset", typeof(T)) as T;
80-
#endif
8177
}
8278
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#if UNITY_EDITOR
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace NuclearBand
6+
{
7+
public static class SODatabaseInternal
8+
{
9+
public static T GetModelForEdit<T>(string path) where T : DataNode
10+
{
11+
return AssetDatabase.LoadAssetAtPath(SODatabaseSettings.Path + path + ".asset", typeof(T)) as T;
12+
}
13+
14+
public static void CreateFolder(string path)
15+
{
16+
var folders = path.Split('/');
17+
var fullPath = SODatabaseSettings.Path.TrimEnd('/');
18+
foreach (var folder in folders)
19+
{
20+
var prevFullPath = fullPath;
21+
fullPath += "/" + folder;
22+
23+
if (AssetDatabase.IsValidFolder(fullPath))
24+
continue;
25+
26+
AssetDatabase.CreateFolder(prevFullPath, folder);
27+
28+
}
29+
AssetDatabase.SaveAssets();
30+
AssetDatabase.Refresh();
31+
}
32+
33+
public static T CreateModel<T>(string path, string name) where T : DataNode
34+
{
35+
var fullPath = SODatabaseSettings.Path + path + "/" + name;
36+
37+
var model = GetModelForEdit<T>(fullPath);
38+
if (model != null)
39+
return model;
40+
41+
CreateFolder(path);
42+
var obj = ScriptableObject.CreateInstance(typeof(T)) as T;
43+
AssetDatabase.CreateAsset(obj, fullPath + ".asset");
44+
AssetDatabase.SaveAssets();
45+
AssetDatabase.Refresh();
46+
return obj;
47+
}
48+
}
49+
}
50+
#endif

Packages/com.nuclearband.sodatabase/Runtime/SODatabaseInternal.cs.meta

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

UserSettings/EditorUserSettings.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ EditorUserSettings:
99
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
1010
flags: 0
1111
RecentlyUsedScenePath-1:
12-
value: 3350570d04520c48420d032f5e2d4a131a1219382e292834633a1237e3f4353ae3f433a6d43b322c3507fc73373f0c2ffe0f462eee0a071b1d0bac3d12fa1e165fd016cc0ed1
12+
value: 22424703114646680c031c2e15301023171a0826296703282c240d3fe7b1073be7e933a7f234362820
1313
flags: 0
1414
RecentlyUsedScenePath-2:
15-
value: 22424703114646680c031c2e15301023171a0826296703282c240d3fe7b1073be7e933a7f234362820
15+
value: 3350570d04520c48420d032f5e2d4a131a1219382e292834633a1237e3f4353ae3f433a6d43b322c3507fc73373f0c2ffe0f462eee0a071b1d0bac3d12fa1e165fd016cc0ed1
1616
flags: 0
1717
vcSharedLogLevel:
1818
value: 0d5e400f0650

0 commit comments

Comments
 (0)