#if HAVE_NODECANVAS
using System;
using UnityEngine;
using UnityEngine.UI;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
namespace Framework.Dialogue {
///
/// Allows a transition only if the player picked a specific choice in the last dialogue
///
[Category("Dialogue")]
public class DialogueChoiceCondition : ConditionTask {
/// Choice on which this condition will pass
public int ChoiceIndex = 0;
/// Generates a string describing the condition
protected override string info {
get { return "Choice " + this.ChoiceIndex.ToString() + " made"; }
}
/// Checks whether the condition is fulfilled
/// True if the user made the required dialogue choice
protected override bool OnCheck() {
return (getChoiceIndexFromBlackboard() == this.ChoiceIndex);
}
/// Fetches the index of the selected dialogue choice from the blackboard
/// The index of the selected choice from the blackboard
private int? getChoiceIndexFromBlackboard() {
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 -1;
}
// If it's null, we'll already have complaine in OnInit()!
Variable choiceIndexVariable = choiceBlackboard.GetVariable(
ChoiceIndexVariableName, typeof(int)
);
if(choiceIndexVariable == null) {
return null;
} else {
return (int)choiceIndexVariable.value;
}
}
}
} // namespace Framework.Dialogue
#endif // HAVE_NODECANVAS