-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventSystem.cs
More file actions
223 lines (204 loc) · 7.82 KB
/
EventSystem.cs
File metadata and controls
223 lines (204 loc) · 7.82 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
using System.Reflection;
using System;
namespace RandomizerMod
{
public class EventSystem : MonoBehaviour
{
#region variables
public enum Events
{
Speed, // ускоряет игрока
Cheater, // врубает рандом чит
Dementia, // наркоманские эффекты
Sphere, // создает сферу
NPCTeleport, // тепает нпс вокруг игрока
Balloons, // спавнит шарики
Grounded, // нету доп прыжков
Runner, // вечно бежит прямо
}
public static EventSystem Instance;
private bool _ShowingEvent = false;
private bool _writeText = true;
private Events _CurEvent;
private Events _LastEvent;
private string _event;
private GameObject _plrObj;
private FirstPersonController _fps;
private Cheats _cheats;
private inventario _inventory;
private static FieldInfo _canCheat;
private Coroutine _typingCoroutine;
#endregion
#region CORE
void Start()
{
Instance = this;
_fps = FindObjectOfType<FirstPersonController>(); // ищет по компоненту на обьекте компонент
_cheats = FindObjectOfType<Cheats>();
_inventory = FindObjectOfType<inventario>();
_plrObj = _fps.gameObject;
_canCheat = typeof(Cheats).GetField("trucosPuedenActivarse", BindingFlags.NonPublic | BindingFlags.Instance);
_canCheat.SetValue(_cheats, true);
_cheats.CheatsActivated = true;
} // инитиализация
T Gen<T>(T min, T max)
{
if (typeof(T) == typeof(int))
return (T)(object)UnityEngine.Random.Range((int)(object)min, (int)(object)max);
if (typeof(T) == typeof(float))
return (T)(object)UnityEngine.Random.Range((float)(object)min, (float)(object)max);
if (typeof(T) == typeof(Vector3))
{
var vMin = (Vector3)(object)min;
var vMax = (Vector3)(object)max;
return (T)(object)new Vector3(
UnityEngine.Random.Range(vMin.x, vMax.x),
UnityEngine.Random.Range(vMin.y, vMax.y),
UnityEngine.Random.Range(vMin.z, vMax.z)
);
}
if (typeof(T) == typeof(Color))
{
var cMin = (Color)(object)min;
var cMax = (Color)(object)max;
return (T)(object)new Color(
UnityEngine.Random.Range(cMin.r, cMax.r),
UnityEngine.Random.Range(cMin.g, cMax.g),
UnityEngine.Random.Range(cMin.b, cMax.b),
UnityEngine.Random.Range(cMin.a, cMax.a)
);
}
throw new System.NotSupportedException();
}
#endregion
#region EVENT CORE
public void SetEvent(Events Event = default)
{
_CurEvent = (Events)UnityEngine.Random.Range(0, Enum.GetValues(typeof(Events)).Length);
_ShowingEvent = true;
switch (_CurEvent)
{
case Events.Speed:
TypeText("Gotta go fast");
_fps.SetRunSpeed(Gen<int>(50, 101));
break;
case Events.Cheater:
TypeText("читер");
_cheats.ActivarEfectoAleatorio();
break;
case Events.Sphere:
TypeText("Sphere");
GenerateSphere();
break;
case Events.NPCTeleport:
TypeText("NPC Chaos");
TeleportNPCs();
break;
default:
TypeText($"Надо кароче сделать эвент {_CurEvent}");
break;
}
}// для Инспектора
public void ResetEvent()
{
switch (_CurEvent)
{
case Events.Speed:
_fps.SetRunSpeed(10);
break;
case Events.Cheater:
_cheats.DesactivarTrucos();
break;
}
}
#endregion
#region GUI
public void HideEventText()
{
_ShowingEvent = false;
_event = "";
}
public void TypeText(string text, float speed = 0.05f)
{
if (_writeText)
{
if (_typingCoroutine != null)
StopCoroutine(_typingCoroutine);
_typingCoroutine = StartCoroutine(TypingAnimation(text, speed));
}
}
private IEnumerator TypingAnimation(string text, float speed)
{
_event = "";
foreach (char letter in text.ToCharArray())
{
_event += letter;
float curDelay = speed;
if (char.IsPunctuation(letter))
{
switch (letter)
{
case '.':
case '!':
case '?':
curDelay = speed * 5f;
break;
case ',':
case ':':
case ';':
curDelay = speed * 3f;
break;
default:
curDelay = speed * 2f;
break;
}
}
yield return new WaitForSeconds(curDelay);
}
}
void OnGUI()
{
//if (_showImage)
//{
// GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), _randomImage, ScaleMode.StretchToFill);
//}
if (_ShowingEvent)
{
Texture2D black = new Texture2D(1, 1);
black.SetPixel(0, 0, Color.black * 0.75f);
black.Apply();
GUIStyle EventStyle = new GUIStyle();
EventStyle.normal.textColor = Color.white;
EventStyle.normal.background = black;
EventStyle.fontSize = 45;
EventStyle.fontStyle = FontStyle.Bold;
EventStyle.alignment = TextAnchor.MiddleCenter;
GUI.Box(new Rect(Screen.width / 2 - 375, Screen.height - 150, 750, 125), $"{_event}", EventStyle);
}
}
#endregion
#region EVENTS
void GenerateSphere()
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = new Vector3(_plrObj.transform.position.x + Gen<int>(-2, 2), _plrObj.transform.position.y + 4, _plrObj.transform.position.z + Gen<int>(-2, 2));
sphere.AddComponent<Rigidbody>();
sphere.GetComponent<Renderer>().material.color = Gen<Color>(new Color(0, 0, 0, 0), new Color(1, 1, 1, 1));
}
void TeleportNPCs()
{
foreach (GameObject npc in FindObjectsOfType<GameObject>())
{
if(npc.name.StartsWith("Personaje"))
{
npc.transform.position = new Vector3(_plrObj.transform.position.x + Gen<int>(-10, 10), _plrObj.transform.position.y + Gen<int>(-20, 20), _plrObj.transform.position.z + Gen<int>(-10, 10));
Debug.Log($"Teleported NPC: {npc.name} to {npc.transform.position}");
}
}
}
#endregion
}
}