-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathIsNPCSayingTheLineSO.cs
More file actions
61 lines (51 loc) · 1.42 KB
/
IsNPCSayingTheLineSO.cs
File metadata and controls
61 lines (51 loc) · 1.42 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
using UnityEngine;
using UnityEngine.Localization;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "IsNPCSayingTheLine", menuName = "State Machines/Conditions/Is NPC Saying The Line")]
public class IsNPCSayingTheLineSO : StateConditionSO
{
[SerializeField] private DialogueLineChannelSO _onLineDisplayed = default;
[SerializeField] private ActorSO _protagonistActor;
protected override Condition CreateCondition() => new IsNPCSayingTheLineCondition(_onLineDisplayed, _protagonistActor);
}
public class IsNPCSayingTheLineCondition : Condition
{
private DialogueLineChannelSO _sayLineEvent;
private ActorSO _protagonistActor;
private bool _isNPCSayingTheLine = false;
public IsNPCSayingTheLineCondition(DialogueLineChannelSO sayLineEvent, ActorSO protagonistActor)
{
_sayLineEvent = sayLineEvent;
_protagonistActor = protagonistActor;
}
protected override bool Statement()
{
return _isNPCSayingTheLine;
}
public override void OnStateEnter()
{
if (_sayLineEvent != null)
{
_sayLineEvent.OnEventRaised += OnLineDisplayed;
}
}
public override void OnStateExit()
{
if (_sayLineEvent != null)
{
_sayLineEvent.OnEventRaised -= OnLineDisplayed;
}
}
private void OnLineDisplayed(LocalizedString line, ActorSO actor)
{
if (actor.ActorName == _protagonistActor.ActorName)
{
_isNPCSayingTheLine = false;
}
else
{
_isNPCSayingTheLine = true;
}
}
}