Skip to content

Commit

Permalink
feat: Added scale property to SpawnInfo (#512)
Browse files Browse the repository at this point in the history
Update SpawnInfo with scale (+new overloads)
  • Loading branch information
LeeTwentyThree committed Dec 19, 2023
1 parent 7058c3d commit f92156c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
63 changes: 55 additions & 8 deletions Nautilus/Handlers/CoordinatedSpawnsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,26 @@ public struct SpawnInfo : IEquatable<SpawnInfo>
internal Quaternion Rotation { get; }
[JsonProperty]
internal SpawnType Type { get; }
[JsonProperty]
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;

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="techType">TechType to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition)
: this(default, techType, spawnPosition, Quaternion.identity) { }
: this(default, techType, spawnPosition, Quaternion.identity, Vector3.one) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="classId">ClassID to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
public SpawnInfo(string classId, Vector3 spawnPosition)
: this(classId, default, spawnPosition, Quaternion.identity) { }
: this(classId, default, spawnPosition, Quaternion.identity, Vector3.one) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -90,7 +94,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition)
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation)
: this(default, techType, spawnPosition, rotation) { }
: this(default, techType, spawnPosition, rotation, Vector3.one) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -99,7 +103,27 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation)
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation)
: this(classId, default, spawnPosition, rotation) { }
: this(classId, default, spawnPosition, rotation, Vector3.one) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="techType">TechType to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale)
: this(default, techType, spawnPosition, rotation, scale) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="classId">ClassID to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation, Vector3 scale)
: this(classId, default, spawnPosition, rotation, scale) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -108,7 +132,7 @@ public SpawnInfo(string classId, Vector3 spawnPosition, Quaternion rotation)
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation)
: this(default, techType, spawnPosition, Quaternion.Euler(rotation)) { }
: this(default, techType, spawnPosition, Quaternion.Euler(rotation), Vector3.one) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
Expand All @@ -117,10 +141,30 @@ public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation)
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation)
: this(classId, default, spawnPosition, Quaternion.Euler(rotation)) { }
: this(classId, default, spawnPosition, Quaternion.Euler(rotation), Vector3.one) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="techType">TechType to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(TechType techType, Vector3 spawnPosition, Vector3 rotation, Vector3 scale)
: this(default, techType, spawnPosition, Quaternion.Euler(rotation), scale) { }

/// <summary>
/// Initializes a new <see cref="SpawnInfo"/>.
/// </summary>
/// <param name="classId">ClassID to spawn.</param>
/// <param name="spawnPosition">Position to spawn into.</param>
/// <param name="rotation">Rotation to spawn at.</param>
/// <param name="scale">Scale to spawn with.</param>
public SpawnInfo(string classId, Vector3 spawnPosition, Vector3 rotation, Vector3 scale)
: this(classId, default, spawnPosition, Quaternion.Euler(rotation), scale) { }

[JsonConstructor]
internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Quaternion rotation)
internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Quaternion rotation, Vector3 scale)
{
ClassId = classId;
TechType = techType;
Expand All @@ -131,6 +175,7 @@ internal SpawnInfo(string classId, TechType techType, Vector3 spawnPosition, Qua
default(TechType) => SpawnType.ClassId,
_ => SpawnType.TechType
};
Scale = scale;
}

/// <summary>
Expand Down Expand Up @@ -165,6 +210,7 @@ public override int GetHashCode()
hash = (hash * 7) + SpawnPosition.GetHashCode();
hash = (hash * 7) + Rotation.GetHashCode();
hash = (hash * 7) + Type.GetHashCode();
hash = (hash * 7) + ActualScale.GetHashCode();
return hash;
}
}
Expand All @@ -186,7 +232,8 @@ public bool Equals(SpawnInfo other)
&& other.ClassId == ClassId
&& other.SpawnPosition == SpawnPosition
&& other.Rotation == Rotation
&& other.Type == Type;
&& other.Type == Type
&& other.ActualScale == ActualScale;
}

internal enum SpawnType
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/MonoBehaviours/EntitySpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ IEnumerator SpawnAsync()
}


GameObject obj = UWE.Utils.InstantiateDeactivated(prefab, spawnInfo.SpawnPosition, spawnInfo.Rotation);
GameObject obj = UWE.Utils.InstantiateDeactivated(prefab, spawnInfo.SpawnPosition, spawnInfo.Rotation, spawnInfo.ActualScale);

LargeWorldEntity lwe = obj.GetComponent<LargeWorldEntity>();

Expand Down

0 comments on commit f92156c

Please sign in to comment.