-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRotatableElementConsumer.cs
More file actions
35 lines (31 loc) · 1.39 KB
/
RotatableElementConsumer.cs
File metadata and controls
35 lines (31 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using KSerialization;
using UnityEngine;
using HarmonyLib;
namespace WallPumps
{
[SkipSaveFileSerialization]
[SerializationConfig(MemberSerialization.OptIn)]
public class RotatableElementConsumer : ElementConsumer
{
// When using this, remember to always use RotatablePump too instead of Pump
[SerializeField]
public Vector3 rotatableCellOffset; // Set this instead, since sampleCellOffset will be constantly overridden
}
// The patch to apply GetSampleCell
[HarmonyPatch(typeof(ElementConsumer))]
[HarmonyPatch("GetSampleCell")]
public static class ElementConsumer_GetSampleCell_Patch
{
[HarmonyPriority(-10000)] // Extremely low priority. We want this to happen last, since this will only overwrite RotatableElementConsumer variable
public static void Prefix(ElementConsumer __instance)
{
if (__instance is RotatableElementConsumer)
{
Vector3 rotatableCellOffset = ((RotatableElementConsumer)__instance).rotatableCellOffset;
Rotatable rotatable = __instance.GetComponent<Rotatable>();
if (rotatable != null) __instance.sampleCellOffset = Rotatable.GetRotatedOffset(rotatableCellOffset, rotatable.GetOrientation());
//Debug.Log("GetSampleCell call " + rotatableCellOffset + ", " + __instance.sampleCellOffset);
}
}
}
}