1
1
using System . Collections ;
2
+ using System . Linq ;
2
3
using NitroxClient . GameLogic . InitialSync . Base ;
4
+ using NitroxClient . MonoBehaviours ;
3
5
using NitroxModel . DataStructures . GameLogic ;
6
+ using NitroxModel . Logger ;
4
7
using NitroxModel . Packets ;
5
8
using NitroxModel_Subnautica . Helper ;
6
9
using UnityEngine ;
@@ -10,7 +13,7 @@ namespace NitroxClient.GameLogic.InitialSync
10
13
class CyclopsInitialAsyncProcessor : InitialSyncProcessor
11
14
{
12
15
private readonly Vehicles vehicles ;
13
- private int cyclopsStillLoading = 0 ;
16
+ private int cyclopsLoaded = 0 ;
14
17
private int totalCyclopsToLoad = 0 ;
15
18
private WaitScreen . ManualWaitItem waitScreenItem ;
16
19
@@ -22,34 +25,35 @@ public CyclopsInitialAsyncProcessor(Vehicles vehicles)
22
25
public override IEnumerator Process ( InitialPlayerSync packet , WaitScreen . ManualWaitItem waitScreenItem )
23
26
{
24
27
this . waitScreenItem = waitScreenItem ;
25
-
26
28
vehicles . VehicleCreated += OnVehicleCreated ;
27
29
30
+ totalCyclopsToLoad = packet . Vehicles . Where ( v => v . TechType . Enum ( ) == TechType . Cyclops ) . Count ( ) ;
31
+
28
32
foreach ( VehicleModel vehicle in packet . Vehicles )
29
33
{
30
34
if ( vehicle . TechType . Enum ( ) == TechType . Cyclops )
31
35
{
32
- cyclopsStillLoading ++ ;
36
+ Log . Debug ( $ "Trying to spawn { vehicle } " ) ;
33
37
vehicles . CreateVehicle ( vehicle ) ;
34
38
}
35
39
}
36
40
37
- totalCyclopsToLoad = cyclopsStillLoading ;
38
-
39
- yield return new WaitUntil ( ( ) => cyclopsStillLoading == 0 ) ;
41
+ yield return new WaitUntil ( ( ) => cyclopsLoaded == totalCyclopsToLoad ) ;
40
42
}
41
43
42
44
private void OnVehicleCreated ( GameObject gameObject )
43
45
{
44
- waitScreenItem . SetProgress ( ( totalCyclopsToLoad - cyclopsStillLoading ) , totalCyclopsToLoad ) ;
45
-
46
- cyclopsStillLoading -- ;
46
+ cyclopsLoaded ++ ;
47
+ waitScreenItem . SetProgress ( cyclopsLoaded , totalCyclopsToLoad ) ;
47
48
48
49
// After all cyclops are created
49
- if ( cyclopsStillLoading == 0 )
50
+ if ( cyclopsLoaded == totalCyclopsToLoad )
50
51
{
51
52
vehicles . VehicleCreated -= OnVehicleCreated ;
52
- }
53
+ Log . Debug ( $ "Spawned cyclops { NitroxEntity . GetId ( gameObject ) } ") ;
54
+ }
55
+
56
+ Log . Debug ( $ "We still need to load { totalCyclopsToLoad - cyclopsLoaded } cyclops") ;
53
57
}
54
58
}
55
59
}
0 commit comments