@@ -24,6 +24,7 @@ internal set
2424 }
2525 }
2626 private static NetworkPrefabsList s_PrefabsList ;
27+ private static Dictionary < string , NetworkPrefab > s_PrefabsListPath = new Dictionary < string , NetworkPrefab > ( ) ;
2728
2829 private static void OnPostprocessAllAssets ( string [ ] importedAssets , string [ ] deletedAssets , string [ ] movedAssets , string [ ] movedFromAssetPaths )
2930 {
@@ -48,6 +49,21 @@ bool ProcessImportedAssets(string[] importedAssets1)
4849 var go = AssetDatabase . LoadAssetAtPath < GameObject > ( assetPath ) ;
4950 if ( go . TryGetComponent < NetworkObject > ( out _ ) )
5051 {
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+
5167 s_PrefabsList . List . Add ( new NetworkPrefab { Prefab = go } ) ;
5268 dirty = true ;
5369 }
@@ -103,7 +119,19 @@ bool ProcessDeletedAssets(string[] strings)
103119 return ;
104120 }
105121 }
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+ }
106133
134+ // Process the imported and deleted assets
107135 var markDirty = ProcessImportedAssets ( importedAssets ) ;
108136 markDirty &= ProcessDeletedAssets ( deletedAssets ) ;
109137
0 commit comments