-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogueManager.cs
121 lines (96 loc) · 3.23 KB
/
DialogueManager.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Yarn.Unity;
using TMPro;
using System.Linq;
public class DialogueManager : MonoBehaviour
{
public static bool InDialogue = false;
public DialogueRunner DialogueRunner;
public Image Portrait;
public TextMeshProUGUI Speech;
public TextMeshProUGUI[] OptionButtons;
[System.Serializable]
public struct Character
{
public string name;
public Color color;
public TMP_FontAsset font;
public float fontSize;
}
public Character[] Characters;
private void Awake()
{
DialogueRunner.AddCommandHandler("ChangeCharacter", ChangeCharacter);
DialogueRunner.AddCommandHandler("ChangeCharAnimation", ChangeCharAnimation);
}
public void StartConversation(YarnProgram script, Sprite portrait, RuntimeAnimatorController controller)
{
//set up dialogue ui events, sprites, etc
DialogueRunner.Clear();
DialogueRunner.Add(script);
Portrait.sprite = portrait;
if(controller != null)
{
Portrait.GetComponent<Animator>().runtimeAnimatorController = controller;
}
HandManager.DropAll();
MovementManager.LockCamera();
DialogueRunner.StartDialogue("Start");
InDialogue = true;
}
public void StopConversation()
{
Portrait.GetComponent<Animator>().runtimeAnimatorController = null;
MovementManager.UnlockCamera();
HandManager.HoldRadio();
InDialogue = false;
}
public void ChangeCharacter(string[] parameters)
{
string name = parameters[0];
int option = -1;
if(parameters.Length > 1)
{
string optionStr = parameters[1];
option = int.Parse(optionStr);
}
if (string.IsNullOrEmpty(name))
{
Debug.Log("Change Character called with empty name");
return;
}
Debug.Log(Characters.Length);
var character = Characters.FirstOrDefault(chars => chars.name.ToLower() == name.ToLower());
if(character.name == null)
{
Debug.Log(name + " was not a recognized name by the dialogue manager");
return;
}
if(option == -1)
{
Speech.color = character.color;
Speech.font = character.font;
Speech.fontSize = character.fontSize;
}
else
{
OptionButtons[option].color = character.color;
OptionButtons[option].font = character.font;
OptionButtons[option].fontSize = character.fontSize;
}
}
public void ChangeCharAnimation(string[] parameters)
{
string name = parameters[0];
var animator = Portrait.GetComponent<Animator>();
foreach (AnimatorControllerParameter parameter in animator.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Bool)
animator.SetBool(parameter.name, false);
}
animator.SetBool(name, true);
}
}