Skip to content

Commit

Permalink
feat: WorldEntityInfoUtils class (#384)
Browse files Browse the repository at this point in the history
WorldEntityInfoUtils
  • Loading branch information
LeeTwentyThree authored Jun 2, 2023
1 parent 75eeef6 commit 66a9eb0
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Nautilus/Utility/WorldEntityInfoUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Nautilus.Assets;
using UnityEngine;
using UWE;

namespace Nautilus.Utility;

/// <summary>
/// Utilities related to creating a <see cref="WorldEntityInfo"/> instance.
/// </summary>
public static class WorldEntityInfoUtils
{
/// <summary>
/// Creates a new instance of the <see cref="WorldEntityInfo"/> class based on the given parameters.
/// </summary>
/// <param name="classId">The Class ID of the prefab.</param>
/// <param name="techType">The TechType of the prefab.</param>
/// <param name="cellLevel">The cell level of the prefab (should match whatever is used in the <see cref="LargeWorldEntity"/> component).</param>
/// <param name="slotType">The slot type of the prefab.</param>
/// <param name="zUp">If true, the prefab will use its Z axis as the "up" direction. By default is false, and instead uses its Y axis to determine which way is up.</param>
/// <param name="localScale">The local scale of the prefab when spawned. If left at <see langword="default"/>, aka (0, 0, 0) or <see cref="Vector3.zero"/>, will automatically resolve to <see cref="Vector3.one"/>.</param>
/// <returns>The created <see cref="WorldEntityInfo"/>.</returns>
public static WorldEntityInfo Create(string classId, TechType techType, LargeWorldEntity.CellLevel cellLevel, EntitySlot.Type slotType, bool zUp = false, Vector3 localScale = default)
{
return new WorldEntityInfo()
{
classId = classId,
techType = techType,
cellLevel = cellLevel,
slotType = slotType,
prefabZUp = zUp,
localScale = localScale == default ? Vector3.one : localScale
};
}

/// <summary>
/// Creates a new instance of the <see cref="WorldEntityInfo"/> class based on the given parameters.
/// </summary>
/// <param name="prefabInfo">The object that holds the Class ID and TechType.</param>
/// <param name="cellLevel">The cell level of the prefab (should match whatever is used in the <see cref="LargeWorldEntity"/> component).</param>
/// <param name="slotType">The slot type of the prefab.</param>
/// <param name="zUp">If true, the prefab will use its Z axis as the "up" direction. By default is false, and instead uses its Y axis to determine which way is up.</param>
/// <param name="localScale">The local scale of the prefab when spawned. If left at <see langword="default"/>, aka (0, 0, 0) or <see cref="Vector3.zero"/>, will automatically resolve to <see cref="Vector3.one"/>.</param>
/// <returns>The created <see cref="WorldEntityInfo"/>.</returns>
public static WorldEntityInfo Create(PrefabInfo prefabInfo, LargeWorldEntity.CellLevel cellLevel, EntitySlot.Type slotType, bool zUp = false, Vector3 localScale = default)
{
return new WorldEntityInfo()
{
classId = prefabInfo.ClassID,
techType = prefabInfo.TechType,
cellLevel = cellLevel,
slotType = slotType,
prefabZUp = zUp,
localScale = localScale == default ? Vector3.one : localScale
};
}
}

0 comments on commit 66a9eb0

Please sign in to comment.