-
Notifications
You must be signed in to change notification settings - Fork 1
/
Databox_Light_Patch.cs
67 lines (60 loc) · 2.15 KB
/
Databox_Light_Patch.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using HarmonyLib;
using System.Collections.Generic;
using UnityEngine;
using static ErrorMessage;
namespace Tweaks_Fixes
{
class Databox_Light_Patch
{
public static HashSet<GameObject> databoxLights = new HashSet<GameObject>();
public static GameObject GetClosestToPlayer()
{
GameObject closest = null;
//float shortestDist = float.PositiveInfinity;
//Main.Log("GetClosetToPlayer " + databoxLights.Count);
foreach (GameObject go in databoxLights)
{
if (go && go.activeSelf)
{
float distance = (go.transform.position - Player.main.transform.position).magnitude;
//Main.Log("distance " + distance);
if (distance < 5f)
{
closest = go;
break;
}
}
}
return closest;
}
[HarmonyPatch(typeof(GenericHandTarget), "OnHandClick")]
class GenericHandTarget_OnHandClick_Patch
{
public static void Postfix(GenericHandTarget __instance)
{
if (__instance.GetComponent<BlueprintHandTarget>())
{
GameObject closestLight = GetClosestToPlayer();
if (closestLight != null)
{
//AddDebug("remove light");
closestLight.SetActive(false);
databoxLights.Remove(closestLight);
}
}
}
}
[HarmonyPatch(typeof(VFXVolumetricLight), "Awake")]
class VFXVolumetricLight_Awake_Patch
{
public static void Postfix(VFXVolumetricLight __instance)
{
if (__instance.transform.parent.name.StartsWith("DataboxLight"))
{
//Main.Log("VFXVolumetricLight Awake parent " + __instance.transform.parent.name);
databoxLights.Add(__instance.transform.parent.gameObject);
}
}
}
}
}