-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChoiceManager.cs
131 lines (112 loc) · 4.48 KB
/
ChoiceManager.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
using TMPro;
using UnityEngine;
public class ChoiceManager : MonoBehaviour
{
[Header("References")]
[SerializeField] private DialogueManager _dialogueManager;
[SerializeField] private NPCFinder npcFinder;
public GameObject choiceButtons;
[Header("Player Settings")]
public bool isPlayerResponse;
public bool isNpcResponse;
public bool isPressed;
private bool _isNegativeResponse;
private bool _isPositiveResponse;
private bool _firstNpcDialogue = true;
private bool _firstPlayerDialogue = true;
private PlayerResponse _currentPlayerResponse;
private void Update() => EveryPlayerResponse();
public void PositivePlayerResponse()
{
isPressed = true;
_isPositiveResponse = true;
}
public void NegativePlayerResponse()
{
isPressed = true;
_isNegativeResponse = true;
}
private void EveryPlayerResponse()
{
if (!isPressed) return;
isPressed = false;
choiceButtons.SetActive(false);
isPlayerResponse = true;
_dialogueManager.isTalking = true;
_dialogueManager.npcName.text = npcFinder.GetNpcName.npc.AllDialogue[npcFinder.firstNPCDialogue].
NpcDialogue[_dialogueManager.dialogueOrder].PlayerResponse.NamePlayer;
if (_firstPlayerDialogue)
{
_dialogueManager.dialogueBox.text = isPlayerResponse switch
{
true when _isPositiveResponse => npcFinder.GetNpcName.npc.AllDialogue[npcFinder.firstNPCDialogue]
.NpcDialogue[_dialogueManager.dialogueOrder]
.PlayerResponse.PositiveResponse.ReactPositive,
true when _isNegativeResponse => npcFinder.GetNpcName.npc.AllDialogue[npcFinder.firstNPCDialogue]
.NpcDialogue[_dialogueManager.dialogueOrder]
.PlayerResponse.NegativeResponse.ReactNegative,
_ => _dialogueManager.dialogueBox.text
};
_firstPlayerDialogue = false;
}
else
{
if (!_currentPlayerResponse.HasMorePlayerDialogue())
{
ResetDialogue();
return;
}
_dialogueManager.dialogueBox.text = isPlayerResponse switch
{
true when _isPositiveResponse => _currentPlayerResponse.PositiveResponse.ReactPositive,
true when _isNegativeResponse => _currentPlayerResponse.NegativeResponse.ReactNegative,
_ => _dialogueManager.dialogueBox.text
};
}
}
public void GoToNpcResponse()
{
isPlayerResponse = false;
_dialogueManager.isTalking = true;
isNpcResponse = true;
_dialogueManager.npcName.text = npcFinder.GetNpcName.npc.name;
if (_firstNpcDialogue)
{
_currentPlayerResponse = npcFinder.GetNpcName.npc.AllDialogue[npcFinder.firstNPCDialogue]
.NpcDialogue[_dialogueManager.dialogueOrder].PlayerResponse;
_firstNpcDialogue = false;
}
if (!_currentPlayerResponse.HasMoreNpcDialogue())
{
ResetDialogue();
return;
}
switch (isNpcResponse)
{
case true when _isPositiveResponse:
choiceButtons.SetActive(true);
_dialogueManager.dialogueBox.text = _currentPlayerResponse.PositiveResponse.NpcResponse.NpcDialogue;
_currentPlayerResponse = _currentPlayerResponse.PositiveResponse.NpcResponse.PlayerResponse;
break;
case true when _isNegativeResponse:
choiceButtons.SetActive(true);
_dialogueManager.dialogueBox.text = _currentPlayerResponse.NegativeResponse.NpcResponse.NpcDialogue;
_currentPlayerResponse = _currentPlayerResponse.NegativeResponse.NpcResponse.PlayerResponse;
break;
}
_isPositiveResponse = false;
_isNegativeResponse = false;
}
private void ResetDialogue()
{
_currentPlayerResponse = new PlayerResponse();
_firstNpcDialogue = true;
_firstPlayerDialogue = true;
isPlayerResponse = false;
isNpcResponse = false;
_isPositiveResponse = false;
_isNegativeResponse = false;
_dialogueManager.isTalking = false;
_dialogueManager.OnEndConversation();
}
}