-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStorageBuildProcessor.cs
More file actions
47 lines (38 loc) · 1.17 KB
/
Copy pathStorageBuildProcessor.cs
File metadata and controls
47 lines (38 loc) · 1.17 KB
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
#if UNITY_EDITOR
using System.Linq;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
namespace ToolBox.Loader
{
public class StorageBuildProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder => 0;
public void OnPostprocessBuild(BuildReport report)
{
var loadables = Resources.FindObjectsOfTypeAll<ScriptableObject>()
.Where(x => x is ILoadable
&& AssetDatabase.GetAssetPath(x).Contains("Resources"));
foreach (var loadable in loadables)
Object.DestroyImmediate(loadable, true);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
public void OnPreprocessBuild(BuildReport report)
{
if (!AssetDatabase.IsValidFolder("Assets/Resources"))
AssetDatabase.CreateFolder("Assets", "Resources");
var loadables = Resources.FindObjectsOfTypeAll<ScriptableObject>().Where(x => x is ILoadable);
foreach (var loadable in loadables)
{
var copy = Object.Instantiate(loadable);
var path = $"Assets/Resources/{loadable.name}.asset";
AssetDatabase.CreateAsset(copy, path);
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
}
#endif