diff --git a/Nautilus/Handlers/CoordinatedSpawnsHandler.cs b/Nautilus/Handlers/CoordinatedSpawnsHandler.cs index 44141bdd0..150da21d4 100644 --- a/Nautilus/Handlers/CoordinatedSpawnsHandler.cs +++ b/Nautilus/Handlers/CoordinatedSpawnsHandler.cs @@ -77,6 +77,7 @@ public struct SpawnInfo : IEquatable internal Vector3 Scale { get; } // For the sake of backwards compatibility, a scale of 0x0x0 is automatically converted to 1x1x1. Sorry, no 0x scale entities allowed. internal Vector3 ActualScale => Scale == default ? Vector3.one : Scale; + internal Action OnSpawned { get; } /// /// Initializes a new . @@ -84,7 +85,7 @@ public struct SpawnInfo : IEquatable /// TechType to spawn. /// Position to spawn into. public SpawnInfo(TechType techType, Vector3 spawnPosition) - : this(default, techType, spawnPosition, Quaternion.identity, Vector3.one) { } + : this(default, techType, spawnPosition, Quaternion.identity, Vector3.one, null) { } /// /// Initializes a new . @@ -92,7 +93,7 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition) /// ClassID to spawn. /// Position to spawn into. public SpawnInfo(string classId, Vector3 spawnPosition) - : this(classId, default, spawnPosition, Quaternion.identity, Vector3.one) { } + : this(classId, default, spawnPosition, Quaternion.identity, Vector3.one, null) { } /// /// Initializes a new . @@ -101,7 +102,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition) /// Position to spawn into. /// Rotation to spawn at. public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation) - : this(default, techType, spawnPosition, rotation, Vector3.one) { } + : this(default, techType, spawnPosition, rotation, Vector3.one, null) { } /// /// Initializes a new . @@ -110,7 +111,7 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation) /// Position to spawn into. /// Rotation to spawn at. public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation) - : this(classId, default, spawnPosition, rotation, Vector3.one) { } + : this(classId, default, spawnPosition, rotation, Vector3.one, null) { } /// /// Initializes a new . @@ -120,7 +121,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation) /// Rotation to spawn at. /// Scale to spawn with. public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale) - : this(default, techType, spawnPosition, rotation, scale) { } + : this(default, techType, spawnPosition, rotation, scale, null) { } /// /// Initializes a new . @@ -130,7 +131,7 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation, /// Rotation to spawn at. /// Scale to spawn with. public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation, Vector3 scale) - : this(classId, default, spawnPosition, rotation, scale) { } + : this(classId, default, spawnPosition, rotation, scale, null) { } /// /// Initializes a new . @@ -139,7 +140,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation, Vec /// Position to spawn into. /// Rotation to spawn at. public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation) - : this(default, techType, spawnPosition, Quaternion.Euler(rotation), Vector3.one) { } + : this(default, techType, spawnPosition, Quaternion.Euler(rotation), Vector3.one, null) { } /// /// Initializes a new . @@ -148,7 +149,7 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation) /// Position to spawn into. /// Rotation to spawn at. public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation) - : this(classId, default, spawnPosition, Quaternion.Euler(rotation), Vector3.one) { } + : this(classId, default, spawnPosition, Quaternion.Euler(rotation), Vector3.one, null) { } /// /// Initializes a new . @@ -158,7 +159,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation) /// Rotation to spawn at. /// Scale to spawn with. public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation, Vector3 scale) - : this(default, techType, spawnPosition, Quaternion.Euler(rotation), scale) { } + : this(default, techType, spawnPosition, Quaternion.Euler(rotation), scale, null) { } /// /// Initializes a new . @@ -168,10 +169,32 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation, Vec /// Rotation to spawn at. /// Scale to spawn with. public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation, Vector3 scale) - : this(classId, default, spawnPosition, Quaternion.Euler(rotation), scale) { } + : this(classId, default, spawnPosition, Quaternion.Euler(rotation), scale, null) { } + + /// + /// Initializes a new . + /// + /// TechType to spawn. + /// Position to spawn into. + /// Rotation to spawn at. + /// Scale to spawn with. + /// Callback that is used when the object is successfully spawned. + public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale, Action onSpawned) + : this(default, techType, spawnPosition, rotation, scale, onSpawned) { } + /// + /// Initializes a new . + /// + /// ClassID to spawn. + /// Position to spawn into. + /// Rotation to spawn at. + /// Scale to spawn with. + /// Callback that is used when the object is successfully spawned. + public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation, Vector3 scale, Action onSpawned) + : this(classId, default, spawnPosition, rotation, scale, onSpawned) { } + [JsonConstructor] - internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale) + internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale, Action onSpawned) { ClassId = classId; TechType = techType; @@ -183,6 +206,7 @@ internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Qua _ => SpawnType.TechType }; Scale = scale; + OnSpawned = onSpawned; } /// diff --git a/Nautilus/MonoBehaviours/EntitySpawner.cs b/Nautilus/MonoBehaviours/EntitySpawner.cs index f4826d741..4edda351e 100644 --- a/Nautilus/MonoBehaviours/EntitySpawner.cs +++ b/Nautilus/MonoBehaviours/EntitySpawner.cs @@ -68,6 +68,8 @@ private IEnumerator SpawnAsync() obj.SetActive(true); + spawnInfo.OnSpawned?.Invoke(obj); + LargeWorldEntity.Register(obj); LargeWorldStreamerPatcher.SavedSpawnInfos.Add(spawnInfo);