Documentation for the Unity C# Library
Loading...
Searching...
No Matches
StepItemPostprocessor.cs
Go to the documentation of this file.
1#if UNITY_EDITOR
2using System.IO;
3using PixoVR.Event;
5using UnityEditor;
6
7public class StepItemPostprocessor : AssetPostprocessor
8{
9 private static void OnPostprocessAllAssets(
10 string[] importedAssets,
11 string[] deletedAssets,
12 string[] movedAssets,
13 string[] movedFromAssetPaths
14 )
15 {
16 bool validateScenario = false;
17
18 for (int i = 0; i < deletedAssets.Length; i++)
19 {
20 var asset = deletedAssets[i];
21
22 if (asset.Contains(ScenarioEditorWindow.ScenariosRootPath))
23 {
24 CheckScenarioData(asset);
25 validateScenario = true;
26 }
27 }
28
29 for (int i = 0; i < movedAssets.Length; i++)
30 {
31 var asset = movedAssets[i];
32
33 if (asset.Contains(ScenarioEditorWindow.ScenariosRootPath))
34 {
35 CheckScenarioData(asset);
36 validateScenario = true;
37 }
38 }
39
40 for (int i = 0; i < movedFromAssetPaths.Length; i++)
41 {
42 var asset = movedFromAssetPaths[i];
43
44 if (asset.Contains(ScenarioEditorWindow.ScenariosRootPath))
45 {
46 CheckScenarioData(asset);
47 validateScenario = true;
48 }
49 }
50
51 for (int i = 0; i < importedAssets.Length; i++)
52 {
53 var asset = importedAssets[i];
54
55 if (asset.Contains(ScenarioEditorWindow.ScenariosRootPath))
56 {
57 CheckScenarioData(asset);
58 validateScenario = true;
59 }
60 }
61
62 if (validateScenario)
63 {
64 string[] guids = AssetDatabase.FindAssets(
65 "t:ScenariosDataSO",
66 new[]
67 {
68 Path.GetDirectoryName(ScenarioEditorWindow.ScenariosRootPath)
69 }
70 );
71
72 foreach (string guid in guids)
73 {
74 AssetDatabase.LoadAssetAtPath<ScenariosDataSO>(AssetDatabase.GUIDToAssetPath(guid))?.Validate();
75 }
76 }
77 }
78
79 private static void CheckScenarioData(string asset)
80 {
81 var directory = Path.GetDirectoryName(asset);
82
83 if (directory.Contains(ScenarioEditorWindow.StepsDirectoryName))
84 {
85 string[] guids = AssetDatabase.FindAssets("t:StepsDataSO", new[] {Path.GetDirectoryName(directory)});
86
87 foreach (string guid in guids)
88 {
89 var stepsData = AssetDatabase.LoadAssetAtPath<StepsDataSO>(AssetDatabase.GUIDToAssetPath(guid));
90 stepsData?.Rebuild();
91 }
92 }
93 }
94}
95#endif