-
Notifications
You must be signed in to change notification settings - Fork 0
/
NPC.cs
135 lines (108 loc) · 3.84 KB
/
NPC.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
using System;
using UnityEngine;
using UnityEngine.UI;
using Yarn.Unity;
public class NPC : MonoBehaviour
{
[Range(0,1)]
public float RadioFrequency;
public float Tolerance = 0.05f;
public AudioSource RadioStatic;
public AudioSource RadioWave;
[Range(0, 1)]
public float AudioMaxVolume = 1;
[System.NonSerialized]
public bool EnableRadioHint = true;
private Radio _radio = null;
private InteractiveObject _interaction;
private bool _inFrequency = false;
private bool _hovered = false;
// The Yarn Program we want to load
private DialogueManager _dialogueManager;
public YarnProgram ScriptToLoad;
public Sprite Portrait;
public RuntimeAnimatorController PortraitController;
private ButtonPromptManager _buttonPromptManager;
private OnHoverHint _hint;
// Start is called before the first frame update
void Start()
{
_radio = GameObject.FindGameObjectWithTag("RadioUI")?.GetComponent<Radio>();
_interaction = GetComponent<InteractiveObject>();
_dialogueManager = GameObject.FindGameObjectWithTag("GameController").GetComponent<DialogueManager>();
_buttonPromptManager = GameObject.FindGameObjectWithTag("GameController").GetComponent<ButtonPromptManager>();
_interaction.Interactive = false;
_hint = GetComponent<OnHoverHint>();
if(ObjectiveManager.ProgressTracker < 7 && EnableRadioHint) //not at speaking to people yet
{
_hint.HintText = "I don't feel like talking to people right now.";
}
}
private void Update()
{
if (HandManager.Currently.Equals(HandManager.state.HoldingRadio))
{
CheckIfFrequencyAlign();
AdjustAudio();
}
else
{
RadioWave.volume = 0;
RadioStatic.volume = 0;
if(ObjectiveManager.ProgressTracker >= 7 && EnableRadioHint){
_hint.HintText = "I'll need to use my radio if I want to talk to people.";
}
}
}
private void OnMouseEnter()
{
if(!MoveCamera.Zooming && !MoveCamera.Panning && !DialogueManager.InDialogue)
_hovered = true;
}
private void OnMouseExit()
{
if (!MoveCamera.Zooming && !MoveCamera.Panning)
{
_hovered = false;
_buttonPromptManager.ResetInteractText();
}
}
public void StartConversation()
{
_interaction.Interactive = false;
_interaction.Deselect();
_dialogueManager.StartConversation(ScriptToLoad, Portrait, PortraitController);
}
public void CheckIfFrequencyAlign()
{
if (ObjectiveManager.ProgressTracker >= 7) //can speak to people now
{
if (_radio.Frequency < RadioFrequency + Tolerance && _radio.Frequency > RadioFrequency - Tolerance)
{
_inFrequency = true;
_hint.HintText = "";
if (_hovered)
{
_interaction.MouseEnterFunc();
_buttonPromptManager.ChangeInteractText("Speak");
}
}
else
{
_inFrequency = false;
_hint.HintText = "They can't hear me if the radio is not on the right frequency.";
if (_interaction.Hovered)
{
_interaction.Deselect();
}
}
_interaction.Interactive = _inFrequency;
}
}
public void AdjustAudio()
{
var frequencyDelta = Math.Abs(RadioFrequency - _radio.Frequency);
RadioWave.volume = (1- frequencyDelta)*AudioMaxVolume;
RadioStatic.volume = frequencyDelta * 0.7f;
}
}