@@ -20,7 +20,7 @@ public virtual SVector3 Position
2020 Object . transform . position = value ;
2121 }
2222 }
23- public virtual bool ShouldSerializePosition ( ) => true ;
23+ public virtual bool ShouldSerializePosition ( ) => true ;
2424
2525 [ XmlIgnore , JsonIgnore ]
2626 public virtual ZoneController Controller { get ; protected set ; }
@@ -31,15 +31,16 @@ public virtual SVector3 Position
3131
3232 internal virtual void Initialize ( )
3333 {
34- if ( Object is not null ) return ;
34+ if ( Object ) return ;
3535 UnityObject . DontDestroyOnLoad ( Object = UnityObject . Instantiate ( Prefab ) ) ;
36- UnityObject . Destroy ( Object . GetComponent < Rigidbody > ( ) ) ;
36+ foreach ( var body in Object . GetComponents < Rigidbody > ( ) )
37+ UnityObject . Destroy ( body ) ;
3738 Position = position ; // update position
3839 }
3940 internal virtual void Dispose ( )
4041 {
41- UnityObject . Destroy ( Object ) ;
42- Controller . Dispose ( ) ;
42+ if ( Controller ) UnityObject . Destroy ( Controller ) ;
43+ if ( Object ) UnityObject . Destroy ( Object ) ;
4344 }
4445
4546 public override string ToString ( ) => ToJsonString ( this , true , new ValueTypeToStringJsonConverter ( ) ) ;
@@ -54,25 +55,23 @@ internal override void Initialize()
5455 {
5556 base . Initialize ( ) ;
5657 ( Controller = Object . GetOrAddComponent < TController > ( ) ) . Initialize ( this ) ;
57- #if DEBUG // information for debug
58- Controller . OnPlayerEnter += PlayerEnterHandler ;
59- Controller . OnPlayerExit += PlayerExitHandler ;
60- #endif
58+ Controller . OnPlayerEnter += Debug_PlayerEnterHandler ;
59+ Controller . OnPlayerExit += Debug_PlayerExitHandler ;
6160 }
6261 internal override void Dispose ( )
6362 {
64- #if DEBUG
65- Controller . OnPlayerEnter -= PlayerEnterHandler ;
66- Controller . OnPlayerExit -= PlayerExitHandler ;
67- #endif
63+ Controller . OnPlayerEnter -= Debug_PlayerEnterHandler ;
64+ Controller . OnPlayerExit -= Debug_PlayerExitHandler ;
6865 base . Dispose ( ) ;
6966 }
70- private void PlayerEnterHandler ( Player player )
67+ private void Debug_PlayerEnterHandler ( Player player )
7168 {
69+ if ( ! conf . DebugInformation ) return ;
7270 player . ReceiveMessage ( $ "Enter { Name } ") ;
7371 }
74- private void PlayerExitHandler ( Player player )
72+ private void Debug_PlayerExitHandler ( Player player )
7573 {
74+ if ( ! conf . DebugInformation ) return ;
7675 player . ReceiveMessage ( $ "Exit { Name } ") ;
7776 }
7877}
0 commit comments