#if HAVE_NODECANVAS
using System;
using UnityEngine;
using ParadoxNotion.Design;
using NodeCanvas.Framework;
namespace Framework.Dialogue {
/// Clears the dialogue choice index stored on blackboard
[Category("Dialogue")]
[Icon("Dialogue")]
[Description("Clear dialogue choice index stored on blackboard")]
public class ClearChoiceTask : ActionTask {
/// Provides a summary description of what this action does
protected override string info {
get { return "Clear stored dialogue choice"; }
}
/// Called once when the action is executed
protected override void OnExecute() {
removeChoiceIndexOnBlackboard();
EndAction();
}
/// Removes the index of the selected dialogue choice from the blackboard
private void removeChoiceIndexOnBlackboard() {
const string ChoiceIndexVariableName = "DialogueChoiceIndex";
IBlackboard choiceBlackboard = ownerBlackboard;
if(choiceBlackboard == null) {
Debug.LogError(
"DialogueChoiceCondition could not find a blackboard in its state machine. " +
"A blackboard is required to store the choices made by the player. " +
"Conditions on multiple choice dialogue will not work."
);
return;
}
// If it's null, we'll already have complaine in OnInit()!
Variable choiceIndexVariable = choiceBlackboard.GetVariable(
ChoiceIndexVariableName, typeof(int)
);
if(choiceIndexVariable != null) {
choiceBlackboard.RemoveVariable(ChoiceIndexVariableName);
}
}
}
} // namespace Framework.Dialogue
#endif // HAVE_NODECANVAS