@@ -24,6 +24,7 @@ internal set
24
24
}
25
25
}
26
26
private static NetworkPrefabsList s_PrefabsList ;
27
+ private static Dictionary < string , NetworkPrefab > s_PrefabsListPath = new Dictionary < string , NetworkPrefab > ( ) ;
27
28
28
29
private static void OnPostprocessAllAssets ( string [ ] importedAssets , string [ ] deletedAssets , string [ ] movedAssets , string [ ] movedFromAssetPaths )
29
30
{
@@ -48,6 +49,21 @@ bool ProcessImportedAssets(string[] importedAssets1)
48
49
var go = AssetDatabase . LoadAssetAtPath < GameObject > ( assetPath ) ;
49
50
if ( go . TryGetComponent < NetworkObject > ( out _ ) )
50
51
{
52
+ // Make sure we are not duplicating an already existing entry
53
+ if ( s_PrefabsListPath . ContainsKey ( assetPath ) )
54
+ {
55
+ // Is the imported asset different from the one we already have in the list?
56
+ if ( s_PrefabsListPath [ assetPath ] . Prefab . GetHashCode ( ) != go . GetHashCode ( ) )
57
+ {
58
+ // If so remove the one in the list and continue on to add the imported one
59
+ s_PrefabsList . List . Remove ( s_PrefabsListPath [ assetPath ] ) ;
60
+ }
61
+ else // If they are identical, then just ignore the import
62
+ {
63
+ continue ;
64
+ }
65
+ }
66
+
51
67
s_PrefabsList . List . Add ( new NetworkPrefab { Prefab = go } ) ;
52
68
dirty = true ;
53
69
}
@@ -103,7 +119,19 @@ bool ProcessDeletedAssets(string[] strings)
103
119
return ;
104
120
}
105
121
}
122
+ // Clear our asset path to prefab table each time
123
+ s_PrefabsListPath . Clear ( ) ;
124
+
125
+ // Create our asst path to prefab table
126
+ foreach ( var prefabEntry in s_PrefabsList . List )
127
+ {
128
+ if ( ! s_PrefabsListPath . ContainsKey ( AssetDatabase . GetAssetPath ( prefabEntry . Prefab ) ) )
129
+ {
130
+ s_PrefabsListPath . Add ( AssetDatabase . GetAssetPath ( prefabEntry . Prefab ) , prefabEntry ) ;
131
+ }
132
+ }
106
133
134
+ // Process the imported and deleted assets
107
135
var markDirty = ProcessImportedAssets ( importedAssets ) ;
108
136
markDirty &= ProcessDeletedAssets ( deletedAssets ) ;
109
137
0 commit comments