-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHintTrigger.cs
99 lines (77 loc) · 2.41 KB
/
HintTrigger.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
using System.Collections;
using System.Collections.Generic;
using Unity.Burst.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
[System.Serializable]
public class HintSelection
{
public HintAsset hintAsset;
public string hintKey;
public List<string> GetHintKeys()
{
if(hintAsset != null)
{
return hintAsset.HintList.ConvertAll(h => h.HintKey);
}
return new List<string>();
}
}
public class HintTrigger : MonoBehaviour
{
public List<HintSelection> hintSelections; //List of HintSelections containing HintAssets and selected HintKeys
private HintSystem hintSystem;
private void Start()
{
//Find and assign the HintSytstem
hintSystem = FindObjectOfType<HintSystem>();
if (hintSystem == null)
{
Debug.LogError("HintSystem not found in the scene.");
}
ValidateHintSelections();
}
#region Validation
void ValidateHintSelections()
{
foreach (var selection in hintSelections)
{
if (selection.hintAsset == null)
{
Debug.LogError("HintAsset is missing in HintSelection.");
continue;
}
if (string.IsNullOrEmpty(selection.hintKey))
{
Debug.LogError($"HintKey is missing in HintAsset '{selection.hintAsset.name}'.");
}
else
{
var hint = selection.hintAsset.HintList.Find(h => h.HintKey == selection.hintKey);
if (hint == null)
{
Debug.LogError($"HintKey '{selection.hintKey}' not found in HintAsset '{selection.hintAsset.name}'.");
}
}
}
}
#endregion
public void TriggerHint()
{
if (hintSystem == null || hintSelections.Count == 0) return;
foreach (var selection in hintSelections)
{
var hint = selection.hintAsset.HintList.Find(h => h.HintKey == selection.hintKey);
if (hint != null)
{
hintSystem.ShowHint(hint.HintKey);
return; // Exit after triggering the first valid hint
}
}
Debug.LogWarning("No hints found.");
}
public void OnInteract()
{
TriggerHint();
}
}