Warp particles and render queue

This commit is contained in:
TerrificTrifid 2022-11-07 23:27:47 -06:00
parent 9388246de3
commit 53230dfcf3
3 changed files with 44 additions and 33 deletions

View File

@ -188,7 +188,7 @@ namespace NewHorizons.Builder.Body
foreach (var singularity in body.Config.Props.singularities) foreach (var singularity in body.Config.Props.singularities)
{ {
var polarity = singularity.type == SingularityModule.SingularityType.BlackHole; var polarity = singularity.type == SingularityModule.SingularityType.BlackHole;
SingularityBuilder.MakeSingularityProxy(proxy, singularity.position, polarity, singularity.horizonRadius, singularity.distortRadius, singularity.curve); SingularityBuilder.MakeSingularityProxy(proxy, singularity.position, polarity, singularity.horizonRadius, singularity.distortRadius, singularity.curve, singularity.renderQueueOverride);
if (realSize < singularity.distortRadius) realSize = singularity.distortRadius; if (realSize < singularity.distortRadius) realSize = singularity.distortRadius;
} }
} }

View File

@ -89,7 +89,7 @@ namespace NewHorizons.Builder.Body
GameObject newSingularity = null; GameObject newSingularity = null;
newSingularity = MakeSingularity(go, sector, localPosition, polarity, horizonRadius, distortRadius, newSingularity = MakeSingularity(go, sector, localPosition, polarity, horizonRadius, distortRadius,
hasHazardVolume, singularity.targetStarSystem, singularity.curve, singularity.hasAudio); hasHazardVolume, singularity.targetStarSystem, singularity.curve, singularity.hasWarpEffects, singularity.renderQueueOverride);
var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID; var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID;
_singularitiesByID.Add(uniqueID, newSingularity); _singularitiesByID.Add(uniqueID, newSingularity);
@ -133,7 +133,7 @@ namespace NewHorizons.Builder.Body
} }
public static GameObject MakeSingularity(GameObject planetGO, Sector sector, Vector3 position, bool polarity, float horizon, float distort, public static GameObject MakeSingularity(GameObject planetGO, Sector sector, Vector3 position, bool polarity, float horizon, float distort,
bool hasDestructionVolume, string targetStarSystem = null, TimeValuePair[] curve = null, bool makeAudio = true) bool hasDestructionVolume, string targetStarSystem = null, TimeValuePair[] curve = null, bool warpEffects = true, int renderQueue = 2985)
{ {
InitPrefabs(); InitPrefabs();
@ -143,7 +143,7 @@ namespace NewHorizons.Builder.Body
singularity.transform.parent = sector?.transform ?? planetGO.transform; singularity.transform.parent = sector?.transform ?? planetGO.transform;
singularity.transform.position = planetGO.transform.TransformPoint(position); singularity.transform.position = planetGO.transform.TransformPoint(position);
var singularityRenderer = MakeSingularityGraphics(singularity, polarity, horizon, distort); var singularityRenderer = MakeSingularityGraphics(singularity, polarity, horizon, distort, renderQueue);
SingularitySizeController sizeController = null; SingularitySizeController sizeController = null;
if (curve != null) if (curve != null)
@ -156,31 +156,17 @@ namespace NewHorizons.Builder.Body
} }
OWAudioSource oneShotOWAudioSource = null; OWAudioSource oneShotOWAudioSource = null;
if (makeAudio)
{ var singularityAmbience = GameObject.Instantiate(_blackHoleAmbience, singularity.transform);
var singularityAmbience = GameObject.Instantiate(_blackHoleAmbience, singularity.transform); singularityAmbience.name = polarity ? "BlackHoleAmbience" : "WhiteHoleAmbience";
singularityAmbience.name = polarity ? "BlackHoleAmbience" : "WhiteHoleAmbience"; singularityAmbience.SetActive(true);
singularityAmbience.SetActive(true); singularityAmbience.GetComponent<SectorAudioGroup>().SetSector(sector);
singularityAmbience.GetComponent<SectorAudioGroup>().SetSector(sector);
var singularityAudioSource = singularityAmbience.GetComponent<AudioSource>(); var singularityAudioSource = singularityAmbience.GetComponent<AudioSource>();
singularityAudioSource.maxDistance = distort * 2.5f; singularityAudioSource.maxDistance = distort * 2.5f;
singularityAudioSource.minDistance = horizon; singularityAudioSource.minDistance = horizon;
singularityAmbience.transform.localPosition = Vector3.zero; singularityAmbience.transform.localPosition = Vector3.zero;
if (sizeController != null) sizeController.audioSource = singularityAudioSource; if (sizeController != null) sizeController.audioSource = singularityAudioSource;
if (polarity)
{
var blackHoleOneShot = GameObject.Instantiate(_blackHoleEmissionOneShot, singularity.transform);
blackHoleOneShot.name = "BlackHoleEmissionOneShot";
blackHoleOneShot.SetActive(true);
oneShotOWAudioSource = blackHoleOneShot.GetComponent<OWAudioSource>();
var oneShotAudioSource = blackHoleOneShot.GetComponent<AudioSource>();
oneShotAudioSource.maxDistance = distort * 3f;
oneShotAudioSource.minDistance = horizon;
if (sizeController != null) sizeController.oneShotAudioSource = oneShotAudioSource;
}
}
if (polarity) if (polarity)
{ {
@ -206,6 +192,15 @@ namespace NewHorizons.Builder.Body
} }
else else
{ {
var blackHoleOneShot = GameObject.Instantiate(_blackHoleEmissionOneShot, singularity.transform);
blackHoleOneShot.name = "BlackHoleEmissionOneShot";
blackHoleOneShot.SetActive(true);
oneShotOWAudioSource = blackHoleOneShot.GetComponent<OWAudioSource>();
var oneShotAudioSource = blackHoleOneShot.GetComponent<AudioSource>();
oneShotAudioSource.maxDistance = distort * 3f;
oneShotAudioSource.minDistance = horizon;
if (sizeController != null) sizeController.oneShotAudioSource = oneShotAudioSource;
var blackHoleVolume = GameObject.Instantiate(_blackHoleVolume, singularity.transform); var blackHoleVolume = GameObject.Instantiate(_blackHoleVolume, singularity.transform);
blackHoleVolume.name = "BlackHoleVolume"; blackHoleVolume.name = "BlackHoleVolume";
blackHoleVolume.SetActive(true); blackHoleVolume.SetActive(true);
@ -215,6 +210,16 @@ namespace NewHorizons.Builder.Body
var blackHoleSphereCollider = blackHoleVolume.GetComponent<SphereCollider>(); var blackHoleSphereCollider = blackHoleVolume.GetComponent<SphereCollider>();
blackHoleSphereCollider.radius = horizon; blackHoleSphereCollider.radius = horizon;
if (sizeController != null) sizeController.sphereCollider = blackHoleSphereCollider; if (sizeController != null) sizeController.sphereCollider = blackHoleSphereCollider;
if (!warpEffects)
{
Delay.FireOnNextUpdate(() =>
{
foreach (var renderer in blackHoleVolume.GetComponentsInChildren<ParticleSystemRenderer>(true))
{
UnityEngine.Object.Destroy(renderer);
}
});
}
} }
} }
else else
@ -267,7 +272,7 @@ namespace NewHorizons.Builder.Body
return singularity; return singularity;
} }
public static MeshRenderer MakeSingularityGraphics(GameObject singularity, bool polarity, float horizon, float distort) public static MeshRenderer MakeSingularityGraphics(GameObject singularity, bool polarity, float horizon, float distort, int queue = 2985)
{ {
InitPrefabs(); InitPrefabs();
@ -286,15 +291,16 @@ namespace NewHorizons.Builder.Body
meshRenderer.material.SetFloat(MassScale, polarity ? 1f : -1f); meshRenderer.material.SetFloat(MassScale, polarity ? 1f : -1f);
meshRenderer.material.SetFloat(DistortFadeDist, distort - horizon); meshRenderer.material.SetFloat(DistortFadeDist, distort - horizon);
if (!polarity) meshRenderer.material.SetColor(Color1, new Color(1.88f, 1.88f, 1.88f, 1f)); if (!polarity) meshRenderer.material.SetColor(Color1, new Color(1.88f, 1.88f, 1.88f, 1f));
meshRenderer.material.renderQueue = queue;
return meshRenderer; return meshRenderer;
} }
public static GameObject MakeSingularityProxy(GameObject rootObject, MVector3 position, bool polarity, float horizon, float distort, TimeValuePair[] curve = null) public static GameObject MakeSingularityProxy(GameObject rootObject, MVector3 position, bool polarity, float horizon, float distort, TimeValuePair[] curve = null, int queue = 2985)
{ {
InitPrefabs(); InitPrefabs();
var singularityRenderer = MakeSingularityGraphics(rootObject, polarity, horizon, distort); var singularityRenderer = MakeSingularityGraphics(rootObject, polarity, horizon, distort, queue);
if (position != null) singularityRenderer.transform.localPosition = position; if (position != null) singularityRenderer.transform.localPosition = position;
SingularitySizeController sizeController = null; SingularitySizeController sizeController = null;

View File

@ -62,8 +62,13 @@ namespace NewHorizons.External.Modules.VariableSize
public SingularityType type; public SingularityType type;
/// <summary> /// <summary>
/// Whether it has ambient audio /// Whether a black hole emits blue particles upon warping. It doesn't scale, so disabling this for small black holes is recommended
/// </summary> /// </summary>
public bool hasAudio = true; public bool hasWarpEffects = true;
/// <summary>
/// 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;
} }
} }