This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomButton.cs
201 lines (184 loc) · 7.42 KB
/
CustomButton.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Reactor.Extensions;
using Reactor.Unstrip;
using UnhollowerBaseLib;
using UnityEngine;
namespace Pheonix
{
public class CooldownButton
{
public static List<CooldownButton> buttons = new List<CooldownButton>();
public KillButtonManager killButtonManager;
private Color startColorButton = new Color(255, 255, 255);
private Color startColorText = new Color(255, 255, 255);
public Vector2 PositionOffset = Vector2.zero;
public float MaxTimer = 0f;
public float Timer = 0f;
public float EffectDuration = 0f;
public bool isEffectActive;
public bool hasEffectDuration;
public bool enabled = true;
public Category category;
private string ResourceName;
private Action OnClick;
private Action OnEffectEnd;
private HudManager hudManager;
private float pixelsPerUnit;
private bool canUse;
public CooldownButton(Action OnClick, float Cooldown, string ImageEmbededResourcePath, float PixelsPerUnit,
Vector2 PositionOffset, Category category, HudManager hudManager, float EffectDuration, Action OnEffectEnd)
{
this.hudManager = hudManager;
this.OnClick = OnClick;
this.OnEffectEnd = OnEffectEnd;
this.PositionOffset = PositionOffset;
this.EffectDuration = EffectDuration;
this.category = category;
pixelsPerUnit = PixelsPerUnit;
MaxTimer = Cooldown;
Timer = MaxTimer;
ResourceName = ImageEmbededResourcePath;
hasEffectDuration = true;
isEffectActive = false;
buttons.Add(this);
this.Start();
}
public CooldownButton(Action OnClick, float Cooldown, string ImageEmbededResourcePath, float pixelsPerUnit,
Vector2 PositionOffset, Category category, HudManager hudManager)
{
this.hudManager = hudManager;
this.OnClick = OnClick;
this.pixelsPerUnit = pixelsPerUnit;
this.PositionOffset = PositionOffset;
this.category = category;
MaxTimer = Cooldown;
Timer = MaxTimer;
ResourceName = ImageEmbededResourcePath;
hasEffectDuration = false;
buttons.Add(this);
this.Start();
}
private void Start()
{
killButtonManager = UnityEngine.Object.Instantiate(hudManager.KillButton, hudManager.transform);
startColorButton = killButtonManager.renderer.color;
startColorText = killButtonManager.TimerText.Color;
killButtonManager.gameObject.SetActive(true);
killButtonManager.renderer.enabled = true;
Texture2D tex = GUIExtensions.CreateEmptyTexture();
Assembly assembly = Assembly.GetExecutingAssembly();
Stream myStream = assembly.GetManifestResourceStream(ResourceName);
byte[] buttonTexture = Reactor.Extensions.Extensions.ReadFully(myStream);
ImageConversion.LoadImage(tex, buttonTexture, false);
killButtonManager.renderer.sprite = GUIExtensions.CreateSprite(tex);
PassiveButton button = killButtonManager.GetComponent<PassiveButton>();
button.OnClick.RemoveAllListeners();
button.OnClick.AddListener((UnityEngine.Events.UnityAction)listener);
void listener()
{
if (Timer < 0f && canUse)
{
killButtonManager.renderer.color = new Color(1f, 1f, 1f, 0.3f);
if (hasEffectDuration)
{
isEffectActive = true;
Timer = EffectDuration;
killButtonManager.TimerText.Color = new Color(0, 255, 0);
}
OnClick();
}
}
}
public bool CanUse()
{
if (PlayerControl.LocalPlayer.Data == null) return false;
switch (category)
{
case Category.Everyone:
{
canUse = true;
break;
}
case Category.OnlyCrewmate:
{
canUse = !PlayerControl.LocalPlayer.Data.IsImpostor;
break;
}
case Category.OnlyImpostor:
{
canUse = PlayerControl.LocalPlayer.Data.IsImpostor;
break;
}
case Category.OnlyPheonix:
{
canUse = PlayerControl.LocalPlayer.isPlayerRole("Pheonix");
break;
}
}
return true;
}
public static void HudUpdate()
{
buttons.RemoveAll(item => item.killButtonManager == null);
for (int i = 0; i < buttons.Count; i++)
{
if (buttons[i].CanUse())
buttons[i].Update();
GameOptionsMenuManager.HudUpdatePatch.BobuxUpdate(buttons[i]);
GameOptionsMenuManager.HudUpdatePatch.WaterUpdate(buttons[i]);
GameOptionsMenuManager.HudUpdatePatch.Deadate(buttons[i]);
}
}
private void Update()
{
if (killButtonManager.transform.localPosition.x > 0f)
killButtonManager.transform.localPosition =
new Vector3((killButtonManager.transform.localPosition.x + 1.3f) * -1,
killButtonManager.transform.localPosition.y, killButtonManager.transform.localPosition.z) +
new Vector3(PositionOffset.x, PositionOffset.y);
if (Timer < 0f)
{
killButtonManager.renderer.color = new Color(1f, 1f, 1f, 1f);
if (isEffectActive)
{
killButtonManager.TimerText.Color = startColorText;
Timer = MaxTimer;
isEffectActive = false;
OnEffectEnd();
}
}
else
{
if (canUse)
Timer -= Time.deltaTime;
killButtonManager.renderer.color = new Color(1f, 1f, 1f, 0.3f);
}
killButtonManager.gameObject.SetActive(canUse);
killButtonManager.renderer.enabled = canUse;
if (canUse)
{
killButtonManager.renderer.material.SetFloat("_Desat", 0f);
killButtonManager.SetCoolDown(Timer, MaxTimer);
}
}
internal delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable);
internal static d_LoadImage iCall_LoadImage;
public static bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
{
if (iCall_LoadImage == null)
iCall_LoadImage = IL2CPP.ResolveICall<d_LoadImage>("UnityEngine.ImageConversion::LoadImage");
var il2cppArray = (Il2CppStructArray<byte>)data;
return iCall_LoadImage.Invoke(tex.Pointer, il2cppArray.Pointer, markNonReadable);
}
public enum Category
{
Everyone,
OnlyCrewmate,
OnlyImpostor,
OnlyPheonix
}
}
}