dv_CR-style_smoke_deflectors/dumb282tweaks/CarPatch.cs

73 lines
2.2 KiB
C#
Raw Normal View History

using DV.ThingTypes;
using HarmonyLib;
using UnityEngine;
2023-11-12 15:35:28 +00:00
using static dumb282tweaks.Main;
namespace dumb282tweaks;
[HarmonyPatch(typeof(TrainCar), "Start")]
class CarPatch {
2023-11-12 18:47:12 +00:00
static void Postfix(ref TrainCar __instance)
{
if(__instance != null && __instance.carType == TrainCarType.LocoSteamHeavy)
{
string bodyPath = "LocoS282A_Body/Static_LOD0/s282_locomotive_body";
Transform s282Body = __instance.transform.Find(bodyPath);
if (s282Body == null)
{
Error($"Couldn't find S282 body on '{__instance.transform.gameObject.name}' -> {bodyPath}");
return;
}
2023-11-12 18:47:12 +00:00
Material s282Mat = s282Body.GetComponent<MeshRenderer>().material;
// Smoke Deflector
switch(Main.Settings.smokeDeflectorType) {
case Settings.SmokeDeflectorType.Witte:
2023-11-12 18:47:12 +00:00
Log("witte");
2023-11-12 18:47:12 +00:00
GameObject witteSmokeDeflector = Object.Instantiate(witteSmokeDeflectorsLoad, __instance.transform);
witteSmokeDeflector.transform.localPosition = new Vector3(0.0f, 2.1f, 5f);
witteSmokeDeflector.transform.localRotation = Quaternion.identity;
2023-11-12 18:47:12 +00:00
foreach (var aMeshRenderer in witteSmokeDeflector.GetComponentsInChildren<MeshRenderer>())
{
aMeshRenderer.material = s282Mat;
}
2023-11-12 18:47:12 +00:00
break;
case Settings.SmokeDeflectorType.Wagner:
Log("witten't");
2023-11-12 18:47:12 +00:00
GameObject wagnerSmokeDeflector = Object.Instantiate(wagnerSmokeDeflectorsLoad, __instance.transform);
wagnerSmokeDeflector.transform.localPosition = new Vector3(0.0f, 2.1f, 5f);
wagnerSmokeDeflector.transform.localRotation = Quaternion.identity;
2023-11-12 18:47:12 +00:00
foreach (var aMeshRenderer in wagnerSmokeDeflector.GetComponentsInChildren<MeshRenderer>())
{
aMeshRenderer.material = s282Mat;
}
break;
}
2023-11-12 18:47:12 +00:00
// Boiler
switch (Main.Settings.boilerType)
{
case Settings.BoilerType.Streamlined:
GameObject streamlinedBoiler = Object.Instantiate(streamlinedBoilerLoad, __instance.transform);
streamlinedBoiler.transform.localPosition = new Vector3(0.0f, 2.15f, 5.1f);
streamlinedBoiler.transform.localRotation = Quaternion.identity;
foreach (var aMeshRenderer in streamlinedBoiler.GetComponentsInChildren<MeshRenderer>())
{
aMeshRenderer.material = s282Mat;
}
2023-11-12 18:47:12 +00:00
break;
}
}
}
}