Ejemplo n.º 1
0
    protected override void OnUse()
    {
        Transform tranform = user.avatar.transform;
        Vector3   origin   = transform.position;

        float beamSize = 1.0f;

        RaycastHit hit;

        if (Physics.SphereCast(origin, beamSize, tranform.forward, out hit, range))
        {
            if (hit.rigidbody != null)
            {
                BehaviorComponent behaviorComponent = hit.rigidbody.GetComponent <BehaviorComponent>();
                if (behaviorComponent != null)
                {
                    Entity entity = behaviorComponent.GetComponent <Entity>();
                    if (entity != null)
                    {
                        behaviorComponent.PushOneShotBehavior(new BehaviorGravity(entity));
                    }
                }
            }
        }

        Debug.DrawRay(
            origin,
            origin + user.avatar.transform.forward * range,
            debugRayColor
            );
    }
Ejemplo n.º 2
0
        private void DrawNodeSelected(int id)
        {
            BehaviorComponent component = BehaviorNode.Selection.BehaviorComponent;

            GUILayout.BeginVertical();
            GUIStyle style = new GUIStyle();

            style.fontStyle = FontStyle.Bold;
            GUILayout.Label("Behavior Type: " + component.GetType().Name, style);

            if (component.GetType() == typeof(ConditionalLambda))
            {
                ConditionalLambda conditional = ((ConditionalLambda)component);

                if (conditional.TestAction != null)
                {
                    conditional.ExpressionObjects.Clear();
                    conditional.TestAction.Invoke(conditional);

                    GUILayout.Label("Conditional Description: " + conditional.ConditionalDescription);
                    if (conditional.ExpressionObjects != null)
                    {
                        for (int i = 0; i < conditional.ExpressionObjects.Count; i++)
                        {
                            GUILayout.Label("Conditional Object Type: " + conditional.ExpressionObjects[i].GetType().Name);
                            GUILayout.Label("Conditional Object Value: " + conditional.ExpressionObjects[i]);
                        }
                    }

                    GUILayout.Label("Conditional Result: " + conditional.Result);
                }
                else
                {
                    GUILayout.Label("Conditional Result: " + conditional.Result);
                    GUILayout.Label("Conditional Body: " + conditional.Expression);
                    GUILayout.Label("Conditional Not Using Action Constructor for Debugging");
                }
            }
            else
            {
                foreach (FieldInfo field in fields)
                {
                    string name  = field.Name;
                    object value = field.GetValue(component);

                    if (value != null && field.Name != "Node" && field.Name != "NotifyOnExecute" && field.Name != "AddToHistory" && field.Name != "Action")
                    {
                        GUILayout.Label("Field: " + name);
                        GUILayout.Label("Value: " + value);
                    }
                }
            }
            component.NotifyOnExecute = GUILayout.Toggle(component.NotifyOnExecute, "Notify On Execute");
            GUILayout.EndVertical();
        }
Ejemplo n.º 3
0
            public Entity AddBehavior(out BehaviorComponent behaviorComponent)
            {
                behaviorComponent = Substitute.For <BehaviorComponent>();

                var entity = new Entity();

                entity.AddComponent(behaviorComponent);

                _scene.AddEntity(entity);

                return(entity);
            }
Ejemplo n.º 4
0
        private static void GetBehaviorChildNodes(BehaviorComponent behaviorComponent, BehaviorNode topNode)
        {
            y = nodes[0].Position.y;
            for (int i = 0; i < nodes.Count; i++)
            {
                if (y < nodes[i].Position.y)
                {
                    y = nodes[i].Position.y;
                }
            }
            if (y != topNode.Position.y)
            {
                y = y + 35;
            }

            topNode.Position = new Vector2(topNode.Position.x, y);
            x += 200;
            if (behaviorComponent.Behaviors != null)
            {
                float _y = y;
                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].Position == new Vector2(x, y))
                    {
                        _y = _y + 35;
                        topNode.Position = new Vector2(topNode.Position.x, _y);
                    }
                }
                BehaviorNode previousNode = null;
                for (int i = 0; i < behaviorComponent.Behaviors.Length; i++)
                {
                    BehaviorComponent behavior = behaviorComponent.Behaviors[i];
                    BehaviorNode      node     = new BehaviorNode(behavior, new Vector2(x, (_y + (35 * i))));
                    if (previousNode != null)
                    {
                        node.Position = new Vector2(x, previousNode.Position.y + 35);
                    }
                    node.BehaviorComponent = behavior;
                    node.TopNode           = topNode;
                    nodes.Add(node);

                    if (behavior.Behaviors != null)
                    {
                        GetBehaviorChildNodes(behavior, node);
                    }
                    previousNode = node;
                }
            }
            x -= 200;
        }
Ejemplo n.º 5
0
    private void OnTriggerEnter(Collider collider)
    {
        GameObject gameObject = collider.gameObject;

        if (gameObject.CompareTag("Pet"))
        {
            BehaviorComponent behaviorComponent = gameObject.GetComponent <BehaviorComponent>();
            Entity            entity            = gameObject.GetComponent <Entity>();
            if (entity != null && behaviorComponent != null)
            {
                behaviorComponent.PushOneShotBehavior(new BehaviorScore(entity));
            }
        }
    }
Ejemplo n.º 6
0
    public Portable Lift()
    {
        rb.isKinematic = false;
        rb.useGravity  = false;

        BehaviorComponent behaviorComponent = GetComponent <BehaviorComponent>();

        if (behaviorComponent)
        {
            mBehaviorHeld = new BehaviorHeld(GetComponent <Entity>());
            behaviorComponent.PushOneShotBehavior(mBehaviorHeld);
        }

        mIsHeld = true;

        return(this);
    }
Ejemplo n.º 7
0
        public bool CanInvokeFinalizer(TreeContext context, BehaviorComponent caller)
        {
            if (this.handledThisTick)
            {
                return(true);
            }

            // Check if call hierarchies differ.
            var currentHierarchy = context.CallingHierarchy;

            if (context.OldContext != null)
            {
                return(!currentHierarchy.Matches(context.OldContext.CallingHierarchy));
            }

            return(false);
        }
Ejemplo n.º 8
0
    private void Awake()
    {
        base.Awake();
        PathWalker = gameObject.GetComponent <PathWalker>();

        var _builder = new BehaviourTreeBuilder();

        _builder = _builder.Selector(); // MainNode

        _builder = _builder.StateFulSequence("Patrol")
                   .Inverter("!").Condition("HayEnemigo", () => enemyTransform != null).End()
                   .Condition("EndPath", () => PathWalker.Ended)
                   .Do("FindPath", () => { _ = PathWalker.WalkTo(PathFinderManager.Instance.RandomWalkablePosition); PathWalker.WALK_SPEED = 5; return(BehaviorReturnCode.Success); })
                   .End();

        _builder = _builder.StateFulSequence("FindEnemy")
                   .Inverter("!").Condition("HayEnemigo", () => enemyTransform != null).End()
                   .Inverter("!").Do("BuscarEnemigo", FindEnemy).End()
                   .End();

        _builder = _builder.StateFulSequence("Follow")
                   .Condition("HayEnemigo", () => enemyTransform != null)
                   .Inverter("!").Condition("EstaCerca", () => (enemyTransform.position - transform.position).magnitude < attack_range).End()
                   .Condition("EndPath", () => PathWalker.Ended)
                   .Do("FindPath", () => { _ = PathWalker.WalkTo(enemyTransform.position + ((transform.position - enemyTransform.position).normalized * 1.5f)); return(BehaviorReturnCode.Success); })
                   .End();

        _builder = _builder.StateFulSequence("Attack")
                   .Condition("HayEnemigo", () => enemyTransform != null)
                   .Condition("EstaCerca", () => (enemyTransform.position - transform.position).magnitude < attack_range)
                   .Do("AttackEnemy", AttackEnemy)
                   .End();

        _builder = _builder.End(); // End MainNode

        _root = _builder.Build();
    }
Ejemplo n.º 9
0
 public Counter(int maxIterations, BehaviorComponent behavior)
 {
     this.maxIterations = maxIterations;
     AssignBehaviors(new[] { behavior });
     Name = "Counter";
 }
Ejemplo n.º 10
0
 public BehaviorTree(BehaviorComponent r)
 {
     root = r;
 }
Ejemplo n.º 11
0
 public Inverter(BehaviorComponent behavior)
 {
     AssignBehaviors(new[] { behavior });
     Name = "Inverter";
 }
Ejemplo n.º 12
0
 /// <summary>
 /// executes the behavior every time again
 /// </summary>
 /// <param name="timeToWait">maximum time to wait before executing behavior</param>
 /// <param name="behavior">behavior to run</param>
 public RepeatUntilFail(BehaviorComponent behavior)
 {
     _Behavior = behavior;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// randomly executes the behavior
 /// </summary>
 /// <param name="probability">probability of execution</param>
 /// <param name="randomFunction">function that determines probability to execute</param>
 /// <param name="behavior">behavior to execute</param>
 public RandomDecorator(float probability, Func <float> randomFunction, BehaviorComponent behavior)
 {
     _Probability    = probability;
     _RandomFunction = randomFunction;
     _Behavior       = behavior;
 }
Ejemplo n.º 14
0
 public RepeatUntilSuccessConstant(int maxIterations, BehaviorComponent behavior)
 {
     this.maxIterations = maxIterations;
     AssignBehaviors(new[] { behavior });
     Name = "Counter";
 }
Ejemplo n.º 15
0
 public BinarySelector(BehaviorComponent condition, BehaviorComponent ifTrue, BehaviorComponent ifFalse)
 {
     this.condition = condition;
     this.ifTrue    = ifTrue;
     this.ifFalse   = ifFalse;
 }
Ejemplo n.º 16
0
		public Behavior(BehaviorComponent root){
			_Root = root;
		}
Ejemplo n.º 17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="root"></param>
 public Behavior(IndexSelector root)
 {
     _Root = root;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// returns a success even when the decorated component failed
 /// </summary>
 /// <param name="behavior">behavior to run</param>
 public Failer(BehaviorComponent behavior)
 {
     _Behavior = behavior;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// executes the behavior after a given amount of time in miliseconds has passed
 /// </summary>
 /// <param name="elapsedTimeFunction">function that returns elapsed time</param>
 /// <param name="timeToWait">maximum time to wait before executing behavior</param>
 /// <param name="behavior">behavior to run</param>
 public Timer(Func <int> elapsedTimeFunction, int timeToWait, BehaviorComponent behavior)
 {
     t_ElapsedTimeFunction = elapsedTimeFunction;
     t_Behavior            = behavior;
     t_WaitTime            = timeToWait;
 }
Ejemplo n.º 20
0
 public UtilityPair(UtilityVector vector, BehaviorComponent behavior)
 {
     this.vector   = vector;
     this.behavior = behavior;
 }
Ejemplo n.º 21
0
        public UtilityPair(UtilityVector vector, BehaviorComponent behavior)
        {
			this.vector = vector;
			this.behavior = behavior;
        }
Ejemplo n.º 22
0
    void Start()
    {
        BehaviorComponent behavior = GetComponent <BehaviorComponent>();

        behavior.DefaultTree = this.BakeTree();
    }
 public RepeaterUntilSuccessContinued(int maxIterations, BehaviorComponent behavior)
 {
     this.maxIterations = maxIterations;
     AssignBehaviors(new[] { behavior });
     Name = "RepeaterContinued";
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Returns a failure even when the decorated component succeeded or is running.
 /// </summary>
 /// <param name="behavior">behavior to run</param>
 public Failer(BehaviorComponent behavior)
 {
     this.behavior = behavior;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// randomly executes the behavior
 /// /*    按照随机值比较结果来执行节点,随机值大于指定值则执行节点    */
 /// </summary>
 /// <param name="probability">probability of execution</param>
 /// <param name="randomFunction">function that determines probability to execute</param>
 /// <param name="behavior">behavior to execute</param>
 public RandomDecorator(float probability, Func<float> randomFunction, BehaviorComponent behavior)
 {
     _Probability = probability;
     _RandomFunction = randomFunction;
     _Behavior = behavior;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// executes the behavior every time again
 /// </summary>
 /// <param name="timeToWait">maximum time to wait before executing behavior</param>
 /// <param name="behavior">behavior to run</param>
 public Repeater(BehaviorComponent behavior)
 {
     _Behavior = behavior;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// inverts the given behavior
 /// -Returns Success on Failure or Error
 /// -Returns Failure on Success 
 /// -Returns Running on Running
 /// </summary>
 /// <param name="behavior"></param>
 public Inverter(BehaviorComponent behavior) 
 {
     _Behavior = behavior;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// executes the behavior after a given amount of time in miliseconds has passed
 /// </summary>
 /// <param name="elapsedTimeFunction">function that returns elapsed time</param>
 /// <param name="timeToWait">maximum time to wait before executing behavior</param>
 /// <param name="behavior">behavior to run</param>
 public Timer(Func<int> elapsedTimeFunction, int timeToWait, BehaviorComponent behavior)
 {
     t_ElapsedTimeFunction = elapsedTimeFunction;
     t_Behavior = behavior;
     t_WaitTime = timeToWait;
 }
Ejemplo n.º 29
0
 public void RegisterAgent(BehaviorComponent agent)
 {
     this.idleAgents.Add(agent);
 }
Ejemplo n.º 30
0
        /// <summary>
        /// executes the behavior after a given amount of time in miliseconds has passed
        /// </summary>
        /// <param name="elapsedTimeFunction">function that returns elapsed time</param>
        /// <param name="timeToWait">maximum time to wait before executing behavior</param>
        /// <param name="behavior">behavior to run</param>
		public Timer(TimerDelegate elapsedTimeFunction, int timeToWait, BehaviorComponent behavior)
        {
            _ElapsedTimeFunction = elapsedTimeFunction;
            _Behavior = behavior;
            _WaitTime = timeToWait;
        }
Ejemplo n.º 31
0
 /// <summary>
 /// returns a success even when the decorated component failed
 /// </summary>
 /// <param name="behavior">behavior to run</param>
 public Succeeder(BehaviorComponent behavior)
 {
     _Behavior = behavior;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// executes the behavior based on a counter
 /// -each time Counter is called the counter increments by 1
 /// -Counter executes the behavior when it reaches the supplied maxCount
 /// </summary>
 /// <param name="maxCount">max number to count to</param>
 /// <param name="behavior">behavior to run</param>
 public Counter(int maxCount, BehaviorComponent behavior)
 {
     _MaxCount = maxCount;
     _Behavior = behavior;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// executes the behavior every time again
 /// </summary>
 /// <param name="timeToWait">maximum time to wait before executing behavior</param>
 /// <param name="behavior">behavior to run</param>
 public RepeatUntilFail(BehaviorComponent behavior)
 {
     _Behavior = behavior;
 }
Ejemplo n.º 34
0
 /// <summary>
 ///     executes the behavior every time again
 /// </summary>
 /// <param name="behavior">behavior to run</param>
 public Repeater(BehaviorComponent behavior)
 {
     _behavior = behavior;
 }
Ejemplo n.º 35
0
 public void RegisterAgent(BehaviorComponent agent)
 {
     this.idleAgents.Add(agent);
 }
Ejemplo n.º 36
0
 /// <summary>
 /// executes the behavior based on a counter
 /// -each time Counter is called the counter increments by 1
 /// -Counter executes the behavior when it reaches the supplied maxCount
 /// </summary>
 /// <param name="maxCount">max number to count to</param>
 /// <param name="behavior">behavior to run</param>
 public Counter(int maxCount, BehaviorComponent behavior)
 {
     _MaxCount = maxCount;
     _Behavior = behavior;
 }
Ejemplo n.º 37
0
 /// <summary>
 ///     executes the behavior after a given amount of time in miliseconds has passed
 /// </summary>
 /// <param name="elapsedTimeFunction">function that returns elapsed time</param>
 /// <param name="timeToWait">maximum time to wait before executing behavior</param>
 /// <param name="behavior">behavior to run</param>
 public Timer(Func <int> elapsedTimeFunction, int timeToWait, BehaviorComponent behavior)
 {
     _elapsedTimeFunction = elapsedTimeFunction;
     _behavior            = behavior;
     _waitTime            = timeToWait;
 }
Ejemplo n.º 38
0
 public UntilSuccess(BehaviorComponent behavior)
 {
     AssignBehaviors(new[] { behavior });
     Name = "RepeaterContinued";
 }
Ejemplo n.º 39
0
 public abstract void AddChild(BehaviorComponent behaviorComponent);
Ejemplo n.º 40
0
 /// <summary>
 /// inverts the given behavior
 /// -Returns Success on Failure or Error
 /// -Returns Failure on Success
 /// -Returns Running on Running
 /// </summary>
 /// <param name="behavior"></param>
 public Inverter(BehaviorComponent behavior)
 {
     d_Behavior = behavior;
 }
Ejemplo n.º 41
0
 public OnNotCalled(BehaviorComponent finalizer)
 {
     this.finalizer = finalizer;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// returns a success even when the decorated component failed
 /// </summary>
 /// <param name="behavior">behavior to run</param>
 public Succeeder(BehaviorComponent behavior)
 {
     _Behavior = behavior;
 }
Ejemplo n.º 43
0
 public override void addChild(BehaviorComponent child)
 {
     m_childBehavior = child;
 }