-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathing UnityEngine
More file actions
407 lines (317 loc) · 11.5 KB
/
Copy pathing UnityEngine
File metadata and controls
407 lines (317 loc) · 11.5 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
[33mcommit 40097422259af22d9ff5089043346d3df2e8c0f7[m
Author: anksi <anksilae@gmail.com>
Date: Fri Jan 23 09:43:52 2026 +0200
hint shuffle fixed
[1mdiff --git a/Assets/Scripts/Gameplay/Player/Navigator/ResourceManager.cs b/Assets/Scripts/Gameplay/Player/Navigator/ResourceManager.cs[m
[1mindex 1767083..a1add9a 100644[m
[1m--- a/Assets/Scripts/Gameplay/Player/Navigator/ResourceManager.cs[m
[1m+++ b/Assets/Scripts/Gameplay/Player/Navigator/ResourceManager.cs[m
[36m@@ -542,7 +542,6 @@[m [mpublic class ResourceManager : NetworkBehaviour[m
if (tm != null)[m
tm.NotifyNavigatorGaveLifebuoy();[m
[m
[31m- gm.activePuzzleDoor?.GetPuzzle()?.RevealRandomHint();[m
RevealHintClientRpc();[m
[m
if (gm != null && gm.activePuzzleDoor != null)[m
// File: Assets/Scripts/UI/HUD/TravellerHUD.cs
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class TravellerHUD : MonoBehaviour
{
[Header("Shared Bar (placed manually)")]
public HUDShared sharedBar;
public RectTransform barParent;
[Header("Traveller UI")]
public TMP_Text messageText;
[Tooltip("Root object of the whole puzzle UI (the parent that contains PuzzleScreen + PuzzleObjects).")]
[SerializeField] private GameObject puzzleRoot;
[Header("Puzzle Containers (assign in Inspector)")]
[Tooltip("UI/Puzzle/PuzzleScreen/Border/Content")]
[SerializeField] private RectTransform puzzleScreenContent;
[Header("Puzzle Objects refs")]
[SerializeField] private RectTransform puzzleObjectsPanel; // PuzzleObjects (Panel)
[SerializeField] private RectTransform puzzleObjectsBorder; // PuzzleObjects/Border
[SerializeField] private RectTransform puzzleObjectsContent; // PuzzleObjects/Border/Content (אופציונלי)
public RectTransform PuzzleScreenContent => puzzleScreenContent;
public RectTransform PuzzleObjectsContent => puzzleObjectsContent;
public RectTransform PuzzleObjectsPanel => puzzleObjectsPanel;
public RectTransform PuzzleObjectsBorder => puzzleObjectsBorder;
[Header("Life Flash")]
public Image[] lifeFlashIcons;
[Header("Start Level Message")]
[Tooltip("Message shown at the start of the level (leave empty to disable)")]
public string startLevelMessage = "";
public float startMessageDuration = 3f;
public bool showStartMessageOnStart = true;
[Tooltip("If true, TravellerHUD will subscribe to GameManager.OnLevelStarted instead of showing the message in Start().")]
public bool useGameManagerEvent = true;
[Header("Effects - Bomb Overlay")]
[Tooltip("הספרייט האדום שלך (1920x1080)")]
public Sprite damageOverlaySprite;
[Tooltip("ה-UI Image שעליו נשים את הספרייט. אם לא תשייך, הסקריפט ייצור אחד אוטומטית.")]
public Image damageOverlayImage;
[Range(0f, 1f)]
public float damageOverlayTargetAlpha = 0.65f;
public float overlayFadeIn = 0.05f;
public float overlayFadeOut = 0.10f;
[Header("Optional Fade To Black")]
public CanvasGroup fadeGroup; // CanvasGroup (alpha=0)
private bool flashing = false;
private Coroutine bombEffectCo;
public void SyncPuzzleObjectsPanelToBorder()
{
if (!puzzleObjectsPanel || !puzzleObjectsBorder) return;
// חשוב: לחשב layout עכשיו
LayoutRebuilder.ForceRebuildLayoutImmediate(puzzleObjectsBorder);
// כדי לוודא שגם התוכן עודכן (אם יש Content)
if (puzzleObjectsContent)
LayoutRebuilder.ForceRebuildLayoutImmediate(puzzleObjectsContent);
// Panel מקבל בדיוק את הגובה של Border
puzzleObjectsPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, puzzleObjectsBorder.rect.height);
}
private void Awake()
{
if (!sharedBar)
sharedBar = GetComponentInChildren<HUDShared>(true);
}
private Coroutine startMessageCo;
private bool _subscribedToGM = false;
private void Start()
{
if (!sharedBar)
sharedBar = GetComponentInChildren<HUDShared>(true);
EnsureOverlayImage();
ResetOverlayImmediate();
if (fadeGroup != null)
fadeGroup.alpha = 0f;
// Puzzle hidden by default
if (puzzleRoot != null)
puzzleRoot.SetActive(false);
HUDManager.Instance?.UpdateHUD();
if (!useGameManagerEvent)
{
if (showStartMessageOnStart && !string.IsNullOrEmpty(startLevelMessage))
{
if (startMessageCo != null)
StopCoroutine(startMessageCo);
startMessageCo = StartCoroutine(ShowMessageRoutine(startLevelMessage, startMessageDuration));
}
}
}
public void ShowPuzzle()
{
if (puzzleRoot != null)
puzzleRoot.SetActive(true);
// אופציונלי אבל מומלץ אחרי שבנית UI/הזזת Pieces:
SyncPuzzleObjectsPanelToBorder();
}
private void OnEnable()
{
TrySubscribeToGameManager();
}
private void OnDisable()
{
if (_subscribedToGM && GameManager.Instance != null)
{
GameManager.Instance.OnLevelStarted -= OnGameManagerLevelStarted;
_subscribedToGM = false;
}
}
private void TrySubscribeToGameManager()
{
if (!useGameManagerEvent) return;
if (_subscribedToGM) return;
if (GameManager.Instance == null) return;
GameManager.Instance.OnLevelStarted += OnGameManagerLevelStarted;
_subscribedToGM = true;
}
private void OnGameManagerLevelStarted()
{
if (startMessageCo != null)
StopCoroutine(startMessageCo);
startMessageCo = StartCoroutine(ShowMessageRoutine(startLevelMessage, startMessageDuration));
}
private IEnumerator ShowMessageRoutine(string msg, float duration)
{
ShowMessage(msg);
if (duration > 0f)
yield return new WaitForSeconds(duration);
else
yield return null;
Clear();
startMessageCo = null;
}
public void HidePuzzle()
{
if (puzzleRoot != null)
puzzleRoot.SetActive(false);
}
/// <summary>
/// Clears ONLY runtime spawned puzzle content.
/// Assumes you created Content objects under both borders:
/// UI/Puzzle/PuzzleScreen/Border/Content
/// UI/Puzzle/PuzzleObjects/Border/Content
/// </summary>
public void ClearPuzzleRuntimeContent()
{
ClearChildren(puzzleScreenContent);
ClearChildren(puzzleObjectsContent);
}
private static void ClearChildren(RectTransform parent)
{
if (parent == null) return;
for (int i = parent.childCount - 1; i >= 0; i--)
{
var ch = parent.GetChild(i);
if (ch != null)
Destroy(ch.gameObject);
}
}
// ---------------- Shared HUD ----------------
public void UpdateShared(GameManager gm)
{
sharedBar?.UpdateValues(gm);
}
public void ShowMessage(string msg)
{
if (messageText == null) return;
messageText.gameObject.SetActive(true);
messageText.text = msg;
}
public void SetMessageColor(Color c)
{
if (messageText) messageText.color = c;
}
public void Clear()
{
if (messageText == null) return;
messageText.text = string.Empty;
}
// ---------------- Bomb Overlay ----------------
private void EnsureOverlayImage()
{
if (damageOverlayImage != null)
{
if (damageOverlaySprite != null)
damageOverlayImage.sprite = damageOverlaySprite;
return;
}
var go = new GameObject(
"DamageOverlay_Auto",
typeof(RectTransform),
typeof(CanvasRenderer),
typeof(Image)
);
go.transform.SetParent(transform, false);
var rt = go.GetComponent<RectTransform>();
rt.anchorMin = Vector2.zero;
rt.anchorMax = Vector2.one;
rt.offsetMin = Vector2.zero;
rt.offsetMax = Vector2.zero;
damageOverlayImage = go.GetComponent<Image>();
damageOverlayImage.raycastTarget = false;
damageOverlayImage.preserveAspect = false;
if (damageOverlaySprite != null)
damageOverlayImage.sprite = damageOverlaySprite;
go.transform.SetAsLastSibling();
}
private void ResetOverlayImmediate()
{
if (damageOverlayImage == null)
return;
var c = damageOverlayImage.color;
c.a = 0f;
damageOverlayImage.color = c;
damageOverlayImage.enabled = true;
}
public void PlayBombResetEffect(float redHoldSeconds, float fadeOut, float fadeIn)
{
if (!gameObject.activeInHierarchy)
return;
if (bombEffectCo != null)
StopCoroutine(bombEffectCo);
bombEffectCo = StartCoroutine(BombResetEffectRoutine(redHoldSeconds, fadeOut, fadeIn));
}
private IEnumerator BombResetEffectRoutine(float redHoldSeconds, float fadeOut, float fadeIn)
{
yield return FadeOverlayAlpha(damageOverlayTargetAlpha, overlayFadeIn);
if (fadeGroup != null)
yield return FadeCanvas(fadeGroup, 0f, 1f, fadeOut);
if (redHoldSeconds > 0f)
yield return new WaitForSeconds(redHoldSeconds);
yield return FadeOverlayAlpha(0f, overlayFadeOut);
if (fadeGroup != null)
yield return FadeCanvas(fadeGroup, 1f, 0f, fadeIn);
bombEffectCo = null;
}
private IEnumerator FadeOverlayAlpha(float targetAlpha, float t)
{
if (damageOverlayImage == null)
yield break;
if (t <= 0f)
{
var c0 = damageOverlayImage.color;
c0.a = targetAlpha;
damageOverlayImage.color = c0;
yield break;
}
float startA = damageOverlayImage.color.a;
float time = 0f;
while (time < t)
{
time += Time.deltaTime;
float a = Mathf.Lerp(startA, targetAlpha, time / t);
var c = damageOverlayImage.color;
c.a = a;
damageOverlayImage.color = c;
yield return null;
}
var final = damageOverlayImage.color;
final.a = targetAlpha;
damageOverlayImage.color = final;
}
private IEnumerator FadeCanvas(CanvasGroup cg, float from, float to, float t)
{
if (cg == null)
yield break;
cg.alpha = from;
if (t <= 0f)
{
cg.alpha = to;
yield break;
}
float time = 0f;
while (time < t)
{
time += Time.deltaTime;
cg.alpha = Mathf.Lerp(from, to, time / t);
yield return null;
}
cg.alpha = to;
}
// ---------------- Lives Flash ----------------
public void FlashLives()
{
if (!gameObject.activeInHierarchy || flashing)
return;
StartCoroutine(FlashRoutine());
}
private IEnumerator FlashRoutine()
{
flashing = true;
for (int i = 0; i < 4; i++)
{
foreach (var icon in lifeFlashIcons)
if (icon)
icon.enabled = !icon.enabled;
yield return new WaitForSeconds(0.15f);
}
foreach (var icon in lifeFlashIcons)
if (icon)
icon.enabled = true;
flashing = false;
}
}