Comments (1)
I can confirm that it works perfectly now. Thank you very much for the fast help. :)
I now can abort the Wander node when the player is in range.
Here is my code. Maybe you or someone else can use it in the future:
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
namespace Schema.Builtin.Conditionals
{
[DarkIcon("Conditionals/d_Compare")]
[LightIcon("Conditionals/Compare")]
public class CompareDistance : Conditional
{
public enum ComparisonType
{
Equal,
GreaterThan,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual
}
[Tooltip("LHS Vector 1 for the Distance check")] public BlackboardEntrySelector<Vector3> firstVector;
[Tooltip("LHS Vector 2 for the distance check")] public BlackboardEntrySelector<Vector3> secondVector;
[Tooltip("RHS of the comparison")] public BlackboardEntrySelector<float> distanceToCheck;
[Tooltip("The comparison type for this operation")]
public ComparisonType comparisonType;
public override bool Evaluate(object decoratorMemory, SchemaAgent agent)
{
float distance = Vector3.Distance(firstVector.value, secondVector.value);
switch (comparisonType)
{
case ComparisonType.Equal:
return distance == distanceToCheck.value;
case ComparisonType.GreaterThan:
return distance > distanceToCheck.value;
case ComparisonType.GreaterThanOrEqual:
return distance >= distanceToCheck.value;
case ComparisonType.LessThan:
return distance < distanceToCheck.value;
case ComparisonType.LessThanOrEqual:
return distance <= distanceToCheck.value;
}
return false;
}
public override GUIContent GetConditionalContent()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("If distance (<color=red>{0},{1}</color>) is ", firstVector.name, secondVector.name);
string cName = Regex.Replace(comparisonType.ToString(), "(\\B[A-Z])", " $1").ToLower();
switch (comparisonType)
{
case ComparisonType.Equal:
case ComparisonType.LessThanOrEqual:
case ComparisonType.GreaterThanOrEqual:
sb.AppendFormat("{0} to ", cName);
break;
case ComparisonType.GreaterThan:
case ComparisonType.LessThan:
sb.AppendFormat("{0} ", cName);
break;
}
sb.AppendFormat("<color=red>{0}</color>", distanceToCheck.name);
return new GUIContent(sb.ToString());
}
}
}
from schema.
Related Issues (13)
- Documentation is not clear on Conditional aborts HOT 1
- Connections and some nodes are gone after update to commit 15b26ec4829f64418e47cd99410415604fe16ac7 HOT 3
- BlackboardEntry references are gone after adding an entry to Blackboard HOT 9
- RotateTowardsVector resets references when I hit play HOT 1
- Conditional is evaluated even if corresponding node is not running HOT 3
- I get this error when searching for components. HOT 5
- Missing OnNodeExit() Call on conditional node abort HOT 3
- entryType is NULL HOT 5
- OverlapSphere does not check against Internal Types HOT 2
- Stop Idle Node Execution HOT 5
- Node execution in parallel
- `BlackboardEntrySelector` cannot currently be used in a Modifer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schema.