Add relative to parent option

This commit is contained in:
Noah Pilarski 2022-09-03 12:08:12 -04:00
parent e874f5b012
commit dc53042f92
8 changed files with 178 additions and 120 deletions

View File

@ -159,6 +159,22 @@ namespace NewHorizons.Builder.Props
}
}
if (detail.isRelativeToParent)
{
prop.transform.localPosition = detail.position == null ? Vector3.zero : detail.position;
if (detail.alignToNormal)
{
// Apply the rotation after aligning it with normal
var up = prop.transform.parent.InverseTransformPoint(prop.transform.position).normalized;
prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up);
prop.transform.rotation *= rot;
}
else
{
prop.transform.localRotation = rot;
}
}
return prop;
}

View File

@ -102,8 +102,15 @@ namespace NewHorizons.Builder.Props
{
conversationZone.transform.parent = planetGO.transform.Find(info.pathToAnimController);
}
conversationZone.transform.position = planetGO.transform.TransformPoint(info.position);
if (info.isRelativeToParent) conversationZone.transform.localPosition = info.position;
else conversationZone.transform.position = planetGO.transform.TransformPoint(info.position);
if (!string.IsNullOrEmpty(info.rename))
{
conversationZone.name = info.rename;
}
conversationZone.SetActive(true);
return dialogueTree;

View File

@ -136,19 +136,40 @@ namespace NewHorizons.Builder.Props
}
}
nomaiWallTextObj.transform.position = planetGO.transform.TransformPoint(info.position);
if (info.normal != null)
var pos = (Vector3)(info.position ?? Vector3.zero);
if (info.isRelativeToParent)
{
// In global coordinates (normal was in local coordinates)
var up = (nomaiWallTextObj.transform.position - planetGO.transform.position).normalized;
var forward = planetGO.transform.TransformDirection(info.normal).normalized;
nomaiWallTextObj.transform.localPosition = pos;
if (info.normal != null)
{
// In global coordinates (normal was in local coordinates)
var up = (nomaiWallTextObj.transform.position - planetGO.transform.position).normalized;
var forward = planetGO.transform.TransformDirection(info.normal).normalized;
nomaiWallTextObj.transform.up = up;
nomaiWallTextObj.transform.forward = forward;
nomaiWallTextObj.transform.up = up;
nomaiWallTextObj.transform.forward = forward;
}
if (info.rotation != null)
{
nomaiWallTextObj.transform.localRotation = Quaternion.Euler(info.rotation);
}
}
if (info.rotation != null)
else
{
nomaiWallTextObj.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
nomaiWallTextObj.transform.position = planetGO.transform.TransformPoint(pos);
if (info.normal != null)
{
// In global coordinates (normal was in local coordinates)
var up = (nomaiWallTextObj.transform.position - planetGO.transform.position).normalized;
var forward = planetGO.transform.TransformDirection(info.normal).normalized;
nomaiWallTextObj.transform.up = up;
nomaiWallTextObj.transform.forward = forward;
}
if (info.rotation != null)
{
nomaiWallTextObj.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
}
}
nomaiWallTextObj.SetActive(true);
@ -211,7 +232,9 @@ namespace NewHorizons.Builder.Props
}
}
customScroll.transform.position = planetGO.transform.TransformPoint(info.position ?? Vector3.zero);
var pos = info.position ?? Vector3.zero;
if (info.isRelativeToParent) customScroll.transform.localPosition = pos;
else customScroll.transform.position = planetGO.transform.TransformPoint(pos);
var up = planetGO.transform.InverseTransformPoint(customScroll.transform.position).normalized;
customScroll.transform.rotation = Quaternion.FromToRotation(customScroll.transform.up, up) * customScroll.transform.rotation;
@ -264,7 +287,9 @@ namespace NewHorizons.Builder.Props
}
}
computerObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
var pos = info.position ?? Vector3.zero;
if (info.isRelativeToParent) computerObject.transform.localPosition = pos;
else computerObject.transform.position = planetGO.transform.TransformPoint(pos);
var up = computerObject.transform.position - planetGO.transform.position;
if (info.normal != null) up = planetGO.transform.TransformDirection(info.normal);
@ -291,29 +316,14 @@ namespace NewHorizons.Builder.Props
{
var detailInfo = new PropModule.DetailInfo()
{
position = info.position
position = info.position,
parentPath = info.parentPath,
isRelativeToParent = info.isRelativeToParent,
rename = info.rename
};
var computerObject = DetailBuilder.Make(planetGO, sector, _preCrashComputerPrefab, detailInfo);
computerObject.SetActive(false);
if (!string.IsNullOrEmpty(info.rename))
{
computerObject.name = info.rename;
}
if (!string.IsNullOrEmpty(info.parentPath))
{
var newParent = planetGO.transform.Find(info.parentPath);
if (newParent != null)
{
computerObject.transform.SetParent(newParent, true);
}
else
{
Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}");
}
}
var up = computerObject.transform.position - planetGO.transform.position;
if (info.normal != null) up = planetGO.transform.TransformDirection(info.normal);
computerObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * computerObject.transform.rotation;
@ -380,11 +390,15 @@ namespace NewHorizons.Builder.Props
}
}
cairnObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
var pos = info.position ?? Vector3.zero;
if (info.isRelativeToParent) cairnObject.transform.localPosition = pos;
else cairnObject.transform.position = planetGO.transform.TransformPoint(pos);
if (info.rotation != null)
{
cairnObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
var rot = Quaternion.Euler(info.rotation);
if (info.isRelativeToParent) cairnObject.transform.localRotation = rot;
else cairnObject.transform.rotation = planetGO.transform.TransformRotation(rot);
}
else
{
@ -429,18 +443,13 @@ namespace NewHorizons.Builder.Props
var detailInfo = new PropModule.DetailInfo {
parentPath = info.parentPath,
rotation = info.rotation,
position = info.position
position = info.position,
isRelativeToParent = info.isRelativeToParent,
rename = info.rename
};
var recorderObject = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
recorderObject.SetActive(false);
if (!string.IsNullOrEmpty(info.rename))
{
recorderObject.name = info.rename;
}
recorderObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
if (info.rotation == null)
{
var up = recorderObject.transform.position - planetGO.transform.position;
@ -490,11 +499,15 @@ namespace NewHorizons.Builder.Props
}
}
trailmarkerObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
var pos = info.position ?? Vector3.zero;
if (info.isRelativeToParent) trailmarkerObject.transform.localPosition = pos;
else trailmarkerObject.transform.position = planetGO.transform.TransformPoint(pos);
if (info.rotation != null)
{
trailmarkerObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
var rot = Quaternion.Euler(info.rotation);
if (info.isRelativeToParent) trailmarkerObject.transform.localRotation = rot;
else trailmarkerObject.transform.rotation = planetGO.transform.TransformRotation(rot);
}
else
{

View File

@ -79,8 +79,18 @@ namespace NewHorizons.Builder.Props
}
}
slideReelObj.transform.position = planetGO.transform.TransformPoint((Vector3)(info.position ?? Vector3.zero));
slideReelObj.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler((Vector3)(info.rotation ?? Vector3.zero)));
var pos = (Vector3)(info.position ?? Vector3.zero);
var rot = Quaternion.Euler((Vector3)(info.rotation ?? Vector3.zero));
if (info.isRelativeToParent)
{
slideReelObj.transform.localPosition = pos;
slideReelObj.transform.localRotation = rot;
}
else
{
slideReelObj.transform.position = planetGO.transform.TransformPoint(pos);
slideReelObj.transform.rotation = planetGO.transform.TransformRotation(rot);
}
// Now we replace the slides
int slidesCount = info.slides.Length;
@ -184,8 +194,18 @@ namespace NewHorizons.Builder.Props
}
}
autoProjector.transform.position = planetGO.transform.TransformPoint((Vector3)(info.position ?? Vector3.zero));
autoProjector.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler((Vector3)(info.rotation ?? Vector3.zero)));
var pos = (Vector3)(info.position ?? Vector3.zero);
var rot = Quaternion.Euler((Vector3)(info.rotation ?? Vector3.zero));
if (info.isRelativeToParent)
{
autoProjector.transform.localPosition = pos;
autoProjector.transform.localRotation = rot;
}
else
{
autoProjector.transform.position = planetGO.transform.TransformPoint(pos);
autoProjector.transform.rotation = planetGO.transform.TransformRotation(rot);
}
// Now we replace the slides
int slidesCount = info.slides.Length;
@ -226,23 +246,13 @@ namespace NewHorizons.Builder.Props
var detailInfo = new PropModule.DetailInfo()
{
position = info.position,
rotation = info.rotation,
parentPath = info.parentPath,
isRelativeToParent = info.isRelativeToParent,
scale = 2
};
var g = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
if (!string.IsNullOrEmpty(info.parentPath))
{
var newParent = planetGO.transform.Find(info.parentPath);
if (newParent != null)
{
g.transform.SetParent(newParent, true);
}
else
{
Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}");
}
}
if (g == null)
{
Logger.LogWarning($"Tried to make a vision torch target but couldn't. Do you have the DLC installed?");
@ -292,23 +302,12 @@ namespace NewHorizons.Builder.Props
var detailInfo = new PropModule.DetailInfo()
{
position = info.position,
rotation = info.rotation
rotation = info.rotation,
parentPath = info.parentPath,
isRelativeToParent = info.isRelativeToParent
};
var standingTorch = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
if (!string.IsNullOrEmpty(info.parentPath))
{
var newParent = planetGO.transform.Find(info.parentPath);
if (newParent != null)
{
standingTorch.transform.SetParent(newParent, true);
}
else
{
Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}");
}
}
if (standingTorch == null)
{
Logger.LogWarning($"Tried to make a vision torch target but couldn't. Do you have the DLC installed?");

View File

@ -153,31 +153,14 @@ namespace NewHorizons.Builder.Props
var detailInfo = new PropModule.DetailInfo()
{
position = info.position,
rotation = info.rotation
rotation = info.rotation,
parentPath = info.parentPath,
isRelativeToParent = info.isRelativeToParent,
rename = info.rename
};
var whiteboard = DetailBuilder.Make(go, sector, _whiteboardPrefab, detailInfo);
whiteboard.SetActive(false);
if (!string.IsNullOrEmpty(info.rename))
{
whiteboard.name = info.rename;
}
whiteboard.transform.parent = sector?.transform ?? go.transform;
if (!string.IsNullOrEmpty(info.parentPath))
{
var newParent = go.transform.Find(info.parentPath);
if (newParent != null)
{
whiteboard.transform.parent = newParent;
}
else
{
Logger.LogWarning($"Cannot find parent object at path: {go.name}/{info.parentPath}");
}
}
var decalMat = new Material(_decalMaterial);
decalMat.SetTexture("_MainTex", decal);
decalMat.SetTexture("_EmissionMap", decal);
@ -218,31 +201,14 @@ namespace NewHorizons.Builder.Props
var detailInfo = new PropModule.DetailInfo()
{
position = info.position,
rotation = info.rotation
rotation = info.rotation,
parentPath = info.parentPath,
isRelativeToParent = info.isRelativeToParent,
rename = info.rename
};
var platform = DetailBuilder.Make(go, sector, _remoteCameraPlatformPrefab, detailInfo);
platform.SetActive(false);
if (!string.IsNullOrEmpty(info.rename))
{
platform.name = info.rename;
}
platform.transform.parent = sector?.transform ?? go.transform;
if (!string.IsNullOrEmpty(info.parentPath))
{
var newParent = go.transform.Find(info.parentPath);
if (newParent != null)
{
platform.transform.parent = newParent;
}
else
{
Logger.LogWarning($"Cannot find parent object at path: {go.name}/{info.parentPath}");
}
}
var decalMat = new Material(_decalMaterial);
decalMat.SetTexture("_MainTex", decal);
decalMat.SetTexture("_EmissionMap", decal);
@ -292,8 +258,18 @@ namespace NewHorizons.Builder.Props
}
}
shareStone.transform.position = go.transform.TransformPoint((Vector3)(info.position ?? Vector3.zero));
shareStone.transform.rotation = go.transform.TransformRotation(Quaternion.Euler((Vector3)(info.rotation ?? Vector3.zero)));
var pos = (Vector3)(info.position ?? Vector3.zero);
var rot = Quaternion.Euler((Vector3)(info.rotation ?? Vector3.zero));
if (info.isRelativeToParent)
{
shareStone.transform.localPosition = pos;
shareStone.transform.localRotation = rot;
}
else
{
shareStone.transform.position = go.transform.TransformPoint(pos);
shareStone.transform.rotation = go.transform.TransformRotation(rot);
}
shareStone.GetComponent<SharedStone>()._connectedPlatform = id;

View File

@ -154,7 +154,9 @@ namespace NewHorizons.Builder.Props
}
}
signalGO.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero);
var pos = (Vector3)(info.position ?? Vector3.zero);
if (info.isRelativeToParent) signalGO.transform.localPosition = pos;
else signalGO.transform.position = planetGO.transform.TransformPoint(pos);
signalGO.layer = LayerMask.NameToLayer("AdvancedEffectVolume");
var source = signalGO.AddComponent<AudioSource>();

View File

@ -200,6 +200,11 @@ namespace NewHorizons.External.Modules
/// </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>
/// Should this detail stay loaded even if you're outside the sector (good for very large props)
/// </summary>
@ -425,6 +430,16 @@ namespace NewHorizons.External.Modules
/// Relative path to the xml file defining the dialogue.
/// </summary>
public string xmlFile;
/// <summary>
/// Whether the positional and rotational coordinates are relative to the animation controller instead of the root planet object.
/// </summary>
public bool isRelativeToParent;
/// <summary>
/// An optional rename of this object
/// </summary>
public string rename;
}
[JsonObject]
@ -525,6 +540,11 @@ namespace NewHorizons.External.Modules
/// </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>
@ -615,6 +635,11 @@ namespace NewHorizons.External.Modules
/// The relative path from the planet to the parent of this slideshow. 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;
}
[JsonObject]
@ -814,6 +839,11 @@ namespace NewHorizons.External.Modules
/// </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>
@ -877,6 +907,11 @@ namespace NewHorizons.External.Modules
/// </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>
@ -916,6 +951,11 @@ namespace NewHorizons.External.Modules
/// </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>

View File

@ -80,6 +80,11 @@ namespace NewHorizons.External.Modules
/// The relative path from the planet to the parent of this signal. 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;
}
}
}