-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataNest.cs
60 lines (48 loc) · 1.91 KB
/
DataNest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEditor;
using UnityEngine;
using static NestableDataStores.DataFilePaths;
namespace NestableDataStores {
public abstract class DataNest : DataScriptable {
# if UNITY_EDITOR
// IDataAsset interface
[SerializeReference] [field: HideInInspector] private string _groupName;
sealed public override string GroupName => _groupName;
sealed public override string Name { get; set; }
sealed public override int? Index { get; set; }
public virtual string NestName => GetType().Name;
sealed public override string Dir => $"{BASE_DIR}{GroupName}/{SO_DIR_NAME}/{NestName}/";
// If true, this data nest will create data associated with a different prefab than the parent
protected virtual bool UniquePrefab => false;
public void Initialize(DataScriptable data, int? idx = null) {
_groupName = data.GroupName;
Name = data.Name;
Index = idx;
Prefab = UniquePrefab ? new DataPrefabEditor(this) : data.Prefab;
IDataAsset.CreateAssetFolder(DesiredAssetPath);
EditorApplication.delayCall += () => {
AssetDatabase.CreateAsset(this, DesiredAssetPath);
AssetDatabase.SaveAssets();
EditorUtility.SetDirty(this);
OnFinishedInitializing();
OnEditTimerElapsed();
};
}
public void Delete() {
OnBeginDeletion();
if (UniquePrefab) Prefab.Delete();
EditorApplication.delayCall += () => {
AssetDatabase.DeleteAsset(AssetPath);
AssetDatabase.SaveAssets();
};
}
protected override void OnEditTimerElapsed() {
UpdateAssets();
Prefab?.SaveChanges();
}
protected virtual void UpdateAssets() { }
// If desire customization of initialization and deletion logic
protected virtual void OnFinishedInitializing() { }
protected virtual void OnBeginDeletion() {}
# endif
}
}