Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	NewHorizons/Builder/Props/TornadoBuilder.cs
This commit is contained in:
Ben C 2022-05-21 23:21:54 -04:00
commit bf498b5428
7 changed files with 157 additions and 37 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

View File

@ -9,41 +9,76 @@ namespace NewHorizons.Builder.Props
{ {
public static class TornadoBuilder public static class TornadoBuilder
{ {
private static GameObject upPrefab; private static GameObject _upPrefab;
private static GameObject downPrefab; private static GameObject _downPrefab;
private static GameObject soundPrefab; private static GameObject _hurricanePrefab;
private static GameObject _soundPrefab;
private static Texture2D _mainTexture;
private static Texture2D _detailTexture;
private static readonly int DetailColor = Shader.PropertyToID("_DetailColor"); private static readonly int DetailColor = Shader.PropertyToID("_DetailColor");
private static readonly int TintColor = Shader.PropertyToID("_TintColor"); private static readonly int TintColor = Shader.PropertyToID("_TintColor");
public static void Make(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, bool hasClouds) public static void Make(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, bool hasClouds)
{ {
if (upPrefab == null) if (_upPrefab == null)
{ {
upPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado").InstantiateInactive(); _upPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockUpTornado").InstantiateInactive();
upPrefab.name = "Tornado_Up_Prefab"; _upPrefab.name = "Tornado_Up_Prefab";
} }
if (downPrefab == null) if (_downPrefab == null)
{ {
downPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive(); _downPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive();
downPrefab.name = "Tornado_Down_Prefab"; _downPrefab.name = "Tornado_Down_Prefab";
} }
if (soundPrefab == null) if (_hurricanePrefab == null)
{ {
soundPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive(); _hurricanePrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/Hurricane/").InstantiateInactive();
soundPrefab.name = "AudioRail_Prefab"; // For some reason they put the hurricane at the origin and offset all its children (450)
// Increasing by 40 will keep the bottom above the ground
foreach (Transform child in _hurricanePrefab.transform)
{
child.localPosition += new Vector3(0, 40 - 450, 0);
}
foreach (Transform child in _hurricanePrefab.transform.Find("Effects_GD_Hurricane"))
{
if (child.name.Contains("HurricaneCloudBlend"))
{
child.localPosition = new Vector3(0, 60, 0);
child.localScale = Vector3.one * 1.1f;
}
if (child.name.Equals("Effects_GD_HurricaneCycloneExterior"))
{
child.localScale = new Vector3(0.88f, 1f, 0.88f);
}
}
foreach(var renderer in _hurricanePrefab.GetComponentsInChildren<Renderer>())
{
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
}
if (_soundPrefab == null)
{
_soundPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive();
_soundPrefab.name = "AudioRail_Prefab";
}
if (_mainTexture == null)
{
_mainTexture = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/Tornado_BH_Cyclone_02_d.png");
}
if (_detailTexture == null)
{
_detailTexture = ImageUtilities.GetTexture(Main.Instance, "AssetBundle/Tornado_BH_CycloneDetail_d.png");
} }
float elevation;
Vector3 position; Vector3 position;
if (info.position != null) if (info.position != null)
{ {
position = info.position ?? Random.onUnitSphere * info.elevation; position = info.position ?? Random.onUnitSphere * info.elevation;
elevation = position.magnitude;
} }
else if (info.elevation != 0) else if (info.elevation != 0)
{ {
position = Random.onUnitSphere * info.elevation; position = Random.onUnitSphere * info.elevation;
elevation = info.elevation;
} }
else else
{ {
@ -51,13 +86,19 @@ namespace NewHorizons.Builder.Props
return; return;
} }
var tornadoGO = info.downwards ? downPrefab.InstantiateInactive() : upPrefab.InstantiateInactive(); if (info.type.ToLower() == "hurricane") MakeHurricane(planetGO, sector, info, position);
else MakeTornado(planetGO, sector, info, position, info.type.ToLower() == "downwards");
}
private static void MakeTornado(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, Vector3 position, bool downwards)
{
var tornadoGO = downwards ? _downPrefab.InstantiateInactive() : _upPrefab.InstantiateInactive();
tornadoGO.transform.parent = sector.transform; tornadoGO.transform.parent = sector.transform;
tornadoGO.transform.position = planetGO.transform.TransformPoint(position); tornadoGO.transform.position = planetGO.transform.TransformPoint(position);
tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized)); tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized));
// Add the sound thing before changing the scale // Add the sound thing before changing the scale
var soundGO = soundPrefab.InstantiateInactive(); var soundGO = _soundPrefab.InstantiateInactive();
soundGO.name = "AudioRail"; soundGO.name = "AudioRail";
soundGO.transform.parent = tornadoGO.transform; soundGO.transform.parent = tornadoGO.transform;
soundGO.transform.localPosition = Vector3.zero; soundGO.transform.localPosition = Vector3.zero;
@ -81,7 +122,6 @@ namespace NewHorizons.Builder.Props
audioSource.playOnAwake = true; audioSource.playOnAwake = true;
var scale = info.height == 0 ? 1 : info.height / 10f; var scale = info.height == 0 ? 1 : info.height / 10f;
tornadoGO.transform.localScale = Vector3.one * scale; tornadoGO.transform.localScale = Vector3.one * scale;
// Resize the distance it can be heard from to match roughly with the size // Resize the distance it can be heard from to match roughly with the size
@ -104,28 +144,93 @@ namespace NewHorizons.Builder.Props
tornadoGO.GetComponentInChildren<CapsuleShape>().enabled = true; tornadoGO.GetComponentInChildren<CapsuleShape>().enabled = true;
// Resize it so the force volume goes all the way up
switch (downwards)
{
case true:
tornadoGO.transform.Find("MockDownTornado_FluidCenter").localScale = new Vector3(1, 2f, 1);
break;
default:
tornadoGO.transform.Find("MockUpTornado_FluidCenter").localScale = new Vector3(1, 2f, 1);
break;
}
if (info.tint != null) if (info.tint != null)
{ {
var colour = info.tint.ToColor(); ApplyTint(tornadoGO, info.tint.ToColor(), false, downwards);
foreach (var renderer in tornadoGO.GetComponentsInChildren<Renderer>())
{
renderer.material.color = colour;
renderer.material.SetColor(DetailColor, colour);
renderer.material.SetColor(TintColor, colour);
}
} }
if (info.wanderRate != 0) if (info.wanderRate != 0)
{ {
var wanderer = tornadoGO.AddComponent<NHTornadoWanderController>(); ApplyWanderer(tornadoGO, sector, info);
wanderer.wanderRate = info.wanderRate;
wanderer.wanderDegreesX = info.wanderDegreesX;
wanderer.wanderDegreesZ = info.wanderDegreesZ;
wanderer.sector = sector;
} }
soundGO.SetActive(true); soundGO.SetActive(true);
tornadoGO.SetActive(true); tornadoGO.SetActive(true);
} }
private static void MakeHurricane(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, Vector3 position)
{
var hurricaneGO = _hurricanePrefab.InstantiateInactive();
hurricaneGO.transform.parent = sector.transform;
hurricaneGO.transform.position = planetGO.transform.TransformPoint(position);
hurricaneGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized));
hurricaneGO.GetComponentInChildren<HurricaneFluidVolume>()._density = 8;
// Height of the hurricane is 405 by default
if (info.height != 0) hurricaneGO.transform.localScale = Vector3.one * info.height / 405f;
if (info.tint != null)
{
ApplyTint(hurricaneGO, info.tint.ToColor(), true, false);
}
if (info.wanderRate != 0)
{
ApplyWanderer(hurricaneGO, sector, info);
}
hurricaneGO.SetActive(true);
}
private static void ApplyTint(GameObject go, Color colour, bool hurricane, bool downwards)
{
colour.a = 1f;
var detailTexture = ImageUtilities.TintImage(_detailTexture, colour);
var mainTexture = ImageUtilities.TintImage(_mainTexture, colour);
string materialName;
if (hurricane) materialName = "Hurricane_GD_Cyclone_mat";
else materialName = $"Tornado_BH_Cyclone_{(downwards ? "Down" : "Up")}_mat";
foreach (var renderer in go.GetComponentsInChildren<Renderer>())
{
renderer.material.SetColor("_DetailColor", colour);
renderer.material.SetColor("_TintColor", colour);
if (renderer.material.name.Contains(materialName))
{
renderer.material.SetTexture("_DetailTex", detailTexture);
renderer.material.SetTexture("_MainTex", mainTexture);
renderer.material.SetColor("_FresnelColor", colour);
}
else
{
// If we set the colour on the ones with the material from before, it makes the gradient look bad
renderer.material.color = colour;
}
}
}
private static void ApplyWanderer(GameObject go, Sector sector, PropModule.TornadoInfo info)
{
var wanderer = go.AddComponent<NHTornadoWanderController>();
wanderer.wanderRate = info.wanderRate;
wanderer.wanderDegreesX = info.wanderDegreesX;
wanderer.wanderDegreesZ = info.wanderDegreesZ;
wanderer.sector = sector;
}
} }
} }

View File

@ -120,6 +120,14 @@ namespace NewHorizons.External.Configs
Atmosphere.UseAtmosphereShader = true; Atmosphere.UseAtmosphereShader = true;
} }
} }
if(Props?.Tornados != null)
{
foreach(var tornado in Props.Tornados)
{
if (tornado.downwards) tornado.type = "downwards";
}
}
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

View File

@ -57,10 +57,12 @@ namespace NewHorizons.External.Modules
public float elevation; public float elevation;
public float height = 30; public float height = 30;
public MColor tint; public MColor tint;
public bool downwards;
public float wanderRate; public float wanderRate;
public float wanderDegreesX = 45; public float wanderDegreesX = 45;
public float wanderDegreesZ = 45; public float wanderDegreesZ = 45;
public string type = "upwards";
[System.Obsolete("downwards is deprecated, please use type instead")] public bool downwards;
} }
public class VolcanoInfo public class VolcanoInfo

View File

@ -1086,9 +1086,14 @@
"$ref": "#/$defs/color", "$ref": "#/$defs/color",
"description": "The colour of the tornado." "description": "The colour of the tornado."
}, },
"downwards": { "type": {
"type": "boolean", "type": "string",
"description": "Should it pull things downwards? Will push them upwards by default." "enum": [
"downwards",
"upwards",
"hurricane"
],
"description": "What type of cyclone should this be? Upwards and downwards are both tornados and will push in that direction."
}, },
"wanderRate": { "wanderRate": {
"type": "number", "type": "number",
@ -1097,12 +1102,12 @@
}, },
"wanderDegreesX": { "wanderDegreesX": {
"type": "number", "type": "number",
"description": "Angular distance from the starting position that it will wander, in terms of the angle around the x-axis.", "description": "Angular distance from the starting position that it will wander, in terms of the azimuthal angle (angle of rotation around the polar axis).",
"default": 45 "default": 45
}, },
"wanderDegreesZ": { "wanderDegreesZ": {
"type": "number", "type": "number",
"description": "Angular distance from the starting position that it will wander, in terms of the angle around the z-axis.", "description": "Angular distance from the starting position that it will wander, in terms of the polar angle (angle between the radial vector and the polar axis).",
"default": 45 "default": 45
} }
} }