Use GeneralPropBuilder for singularities

This commit is contained in:
Joshua Thome 2023-03-17 14:32:18 -05:00
parent 3ca6d9a3db
commit 049bb5ba33
2 changed files with 15 additions and 50 deletions

View File

@ -10,6 +10,7 @@ using NewHorizons.Components.SizeControllers;
using System.Drawing;
using Color = UnityEngine.Color;
using NewHorizons.Components.Volumes;
using NewHorizons.Builder.Props;
namespace NewHorizons.Builder.Body
{
@ -139,26 +140,16 @@ namespace NewHorizons.Builder.Body
// polarity true = black, false = white
var singularity = new GameObject(!string.IsNullOrEmpty(rename) ? rename : (polarity ? "BlackHole" : "WhiteHole"));
singularity.transform.parent = sector?.transform ?? planetGO.transform;
var info = new SingularityModule
{
position = position,
rotation = rotation,
isRelativeToParent = isRelativeToParent,
parentPath = parentPath,
rename = rename,
};
if (!string.IsNullOrEmpty(parentPath))
{
var newParent = planetGO.transform.Find(parentPath);
if (newParent != null)
{
singularity.transform.parent = newParent;
}
else
{
Logger.LogError($"Cannot find parent object at path: {planetGO.name}/{parentPath}");
}
}
if (isRelativeToParent)
singularity.transform.localPosition = position;
else
singularity.transform.position = planetGO.transform.TransformPoint(position);
var singularity = GeneralPropBuilder.MakeNew(polarity ? "BlackHole" : "WhiteHole", planetGO, sector, info);
var singularityRenderer = MakeSingularityGraphics(singularity, polarity, horizon, distort, renderQueue);
@ -273,12 +264,6 @@ namespace NewHorizons.Builder.Body
whiteHoleFluidVolume.enabled = true;
}
var rot = Quaternion.Euler(rotation);
if (isRelativeToParent)
singularity.transform.localRotation = rot;
else
singularity.transform.rotation = planetGO.transform.TransformRotation(rot);
singularity.SetActive(true);
return singularity;
}

View File

@ -9,7 +9,7 @@ using Newtonsoft.Json.Converters;
namespace NewHorizons.External.Modules.VariableSize
{
[JsonObject]
public class SingularityModule : VariableSizeModule
public class SingularityModule : PropModule.PositionedAndRotatedPropInfo
{
[JsonConverter(typeof(StringEnumConverter))]
public enum SingularityType
@ -19,6 +19,11 @@ namespace NewHorizons.External.Modules.VariableSize
[EnumMember(Value = @"whiteHole")] WhiteHole = 1
}
/// <summary>
/// Scale this object over time
/// </summary>
public TimeValuePair[] curve;
/// <summary>
/// The uniqueID of the white hole or black hole that is paired to this one. If you don't set a value, entering will kill
/// the player
@ -30,16 +35,6 @@ namespace NewHorizons.External.Modules.VariableSize
/// </summary>
public string uniqueID;
/// <summary>
/// Position of the singularity
/// </summary>
public MVector3 position;
/// <summary>
/// Rotation of the singularity. Determines the direction you come out of a white hole
/// </summary>
public MVector3 rotation;
/// <summary>
/// Radius of the singularity. Note that this isn't the same as the event horizon, but includes the entire volume that
/// has warped effects in it.
@ -75,20 +70,5 @@ namespace NewHorizons.External.Modules.VariableSize
/// Optional override for the render queue. If the singularity is rendering oddly, increasing this to 3000 can help
/// </summary>
[Range(2501f, 3500f)] public int renderQueueOverride = 2985;
/// <summary>
/// The relative path from the planet to the parent of this object. Optional (will default to the root sector).
/// </summary>
public string parentPath;
/// <summary>
/// Whether the positional and rotational coordinates are relative to parent instead of the root planet object.
/// </summary>
public bool isRelativeToParent;
/// <summary>
/// An optional rename of this object
/// </summary>
public string rename;
}
}