-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReefbackPatch.cs
38 lines (34 loc) · 1.16 KB
/
ReefbackPatch.cs
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
36
37
38
using HarmonyLib;
using UnityEngine;
namespace earth88.ReefbackVolumeControl
{
[HarmonyPatch(typeof(Creature))]
internal class PatchCreatures
{
[HarmonyPatch(nameof(Creature.OnEnable))]
[HarmonyPostfix]
public static void OnEnableCreature_Postfix(Creature __instance)
{
if(__instance.GetType() == typeof(Reefback) && __instance.gameObject.GetComponent<ReefbackHook>() == null)
{
__instance.gameObject.AddComponent<ReefbackHook>();
Debug.Log("Reefback loaded and hooked");
}
}
}
public class ReefbackHook : MonoBehaviour
{
float lastVol;
ModOptions modops = ReefbackVolumePlugin.ModOptions;
void Update()
{
if (modops.Volume != lastVol)
{
Reefback reefcomp = gameObject.GetComponent<Reefback>();
float currentVol = modops.Volume;
reefcomp.gameObject.GetComponent<FMOD_CustomLoopingEmitter>().GetEventInstance().setVolume(currentVol * 0.01f);
lastVol = currentVol;
}
}
}
}