Giter Club home page Giter Club logo

Comments (1)

ijisthee avatar ijisthee commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.