Created
January 12, 2015 07:23
-
-
Save tenpn/4c4341d03b373026eb90 to your computer and use it in GitHub Desktop.
From DecisionFlex v1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ****************************************************************************************** | |
// | |
// DecisionFlex, (c) Andrew Fray 2015 | |
// | |
// ****************************************************************************************** | |
using UnityEngine; | |
using System; | |
namespace TenPN.DecisionFlex | |
{ | |
/** | |
\brief | |
Evaulate a context value in relation to a bool, and return one of two scores depending on the result | |
\details | |
For example, fetch the isAlive string from the IContext, and if it is true return a score of one (saying this action can go ahead), otherwise return a score of zero (saying this action can't possibly go ahead). | |
*/ | |
[AddComponentMenu("TenPN/DecisionFlex/Considerations/Bool Consideration")] | |
public class BooleanConsideration : Consideration | |
{ | |
protected override float MakeConsideration(IContext context) | |
{ | |
if (context.HasContext<bool>(m_contextName)) | |
{ | |
bool isFlag = context.GetContext<bool>(m_contextName); | |
return isFlag ? m_scoreIfTrue : m_scoreIfFalse; | |
} | |
else | |
{ | |
throw new UnityException("cannot find bool context of name " + m_contextName); | |
} | |
} | |
////////////////////////////////////////////////// | |
[SerializeField] private string m_contextName; | |
[RangeAttribute(0.0f, 1.0f)] | |
[SerializeField] private float m_scoreIfTrue = 1.0f; | |
[RangeAttribute(0.0f, 1.0f)] | |
[SerializeField] private float m_scoreIfFalse = 0.0f; | |
////////////////////////////////////////////////// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment