-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuildingManagerPatches.cs
60 lines (55 loc) · 2.29 KB
/
BuildingManagerPatches.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
using HarmonyLib;
using System.Reflection;
using UnityEngine;
using Object = UnityEngine.Object;
namespace QolChanges
{
[HarmonyPatch(typeof(BuildingManager))]
public class BuildingManagerPatches
{
[HarmonyPatch("DisplayGhost")]
[HarmonyPostfix]
// Display the building ghost. Called per frame. Calculates the range of the tower at `pos` and draws a circle.
public static void DisplayGhost(BuildingManager __instance, Vector3 pos, string text, GameObject ___currentGhost, GameObject ___thingToBuild)
{
if (___currentGhost.activeInHierarchy)
{
Tower tower = ___thingToBuild.GetComponent<Tower>();
if (tower == null)
return;
Plugin.ghostCircle.towerlessCircle(pos, tower);
}
}
[HarmonyPatch("EnterBuildMode")]
[HarmonyPostfix]
/// <summary>
/// Hide the ghostCircle UI if it is active.
/// </summary>
public static void EnterBuildMode(BuildingManager __instance, GameObject objectToBuild, TowerType type)
{
if (Plugin.ghostCircle == null)
{
Tower tower = objectToBuild.GetComponent<Tower>();
GameObject prefabUI = (GameObject)tower.GetType().GetField(
"towerUI", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(tower);
Plugin.ghostCircle = Object.Instantiate<GameObject>(prefabUI, objectToBuild.transform.position, Quaternion.identity).GetComponent<TowerUI>();
Plugin.ghostCircle.gameObject.SetActive(false);
foreach (Transform child in Plugin.ghostCircle.gameObject.transform)
{
if (child.GetComponent<LineRenderer>() == null)
child.transform.localScale = new Vector3(0, 0, 0);
}
}
Plugin.ghostCircle.gameObject.SetActive(false);
}
[HarmonyPatch("HideGhost")]
[HarmonyPostfix]
public static void HideGhost()
{
if (Plugin.ghostCircle != null)
{
Plugin.ghostCircle.gameObject.SetActive(false);
}
}
}
}