55using UnityEngine ;
66using UnityEngine . SceneManagement ;
77
8+ #if UNITY_6000_7_OR_NEWER
9+ using UnityEditor . Build . Content ;
10+ #endif
11+
812namespace Unity . Netcode . GameObjects . Editor
913{
1014 /// <summary>
11- /// A <see cref="IProcessSceneWithReport"/> that sets the <see cref
15+ /// A build scene callback that sets the <see cref
1216 /// "NetworkObject.InScenePlaced"/> property to true for all <see cref="NetworkObject"/>s in the scene.
1317 /// Ensures that InScenePlaced is always true for all objects in the scene.
1418 /// </summary>
1519 /// <remarks>
16- /// This will always run as the game enters the scene,
20+ /// This will always run as a scene is loaded in playmode or while processed for a player build.
1721 /// </remarks>
22+ #if UNITY_6000_7_OR_NEWER
23+ internal class SetInScenePlaced : AssetPostprocessor
24+ {
25+ public override uint GetVersion ( ) => 1 ;
26+
27+ public override int GetPostprocessOrder ( ) => 0 ;
28+
29+ void OnProcessScene ( Scene scene , SceneImportContext sceneImportContext )
30+ {
31+ InScenePlaceChecks . ReportSceneIssues ( scene , sceneImportContext . awakeDidRun ) ;
32+ }
33+ }
34+ #else
1835 internal class SetInScenePlaced : IProcessSceneWithReport
1936 {
2037 public int callbackOrder => 0 ;
38+
2139 public void OnProcessScene ( Scene scene , BuildReport report )
40+ {
41+ InScenePlaceChecks . ReportSceneIssues ( scene , Application . isPlaying ) ;
42+ }
43+ }
44+ #endif
45+
46+ static class InScenePlaceChecks
47+ {
48+ public static void ReportSceneIssues ( Scene scene , bool hasAwakeRun )
2249 {
2350 var log = new ContextualLogger ( ) ;
2451 log . AddInfo ( scene . name , scene . handle ) ;
@@ -42,15 +69,15 @@ public void OnProcessScene(Scene scene, BuildReport report)
4269 continue ;
4370 }
4471
45- // If already marked, the do nothing.
72+ // If already marked, do nothing.
4673 if ( networkObject . InScenePlaced )
4774 {
4875 continue ;
4976 }
5077
5178 networkObject . InScenePlaced = true ;
52- // Will not be true when making a build and the values are serialized .
53- networkObject . InScenePlacedPostProcessorMarkedDuringRuntime = Application . isPlaying ;
79+ // Mark that awake has run so this could have been a dynamically instantiated object .
80+ networkObject . InScenePlacedPostProcessorMarkedDuringRuntime = hasAwakeRun ;
5481 }
5582 }
5683 }
0 commit comments