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 ); }
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(); }
public Entity AddBehavior(out BehaviorComponent behaviorComponent) { behaviorComponent = Substitute.For <BehaviorComponent>(); var entity = new Entity(); entity.AddComponent(behaviorComponent); _scene.AddEntity(entity); return(entity); }
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; }
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)); } } }
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); }
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); }
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(); }
public Counter(int maxIterations, BehaviorComponent behavior) { this.maxIterations = maxIterations; AssignBehaviors(new[] { behavior }); Name = "Counter"; }
public BehaviorTree(BehaviorComponent r) { root = r; }
public Inverter(BehaviorComponent behavior) { AssignBehaviors(new[] { behavior }); Name = "Inverter"; }
/// <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; }
/// <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; }
public RepeatUntilSuccessConstant(int maxIterations, BehaviorComponent behavior) { this.maxIterations = maxIterations; AssignBehaviors(new[] { behavior }); Name = "Counter"; }
public BinarySelector(BehaviorComponent condition, BehaviorComponent ifTrue, BehaviorComponent ifFalse) { this.condition = condition; this.ifTrue = ifTrue; this.ifFalse = ifFalse; }
public Behavior(BehaviorComponent root){ _Root = root; }
/// <summary> /// /// </summary> /// <param name="root"></param> public Behavior(IndexSelector root) { _Root = root; }
/// <summary> /// returns a success even when the decorated component failed /// </summary> /// <param name="behavior">behavior to run</param> public Failer(BehaviorComponent behavior) { _Behavior = behavior; }
/// <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; }
public UtilityPair(UtilityVector vector, BehaviorComponent behavior) { this.vector = vector; this.behavior = behavior; }
void Start() { BehaviorComponent behavior = GetComponent <BehaviorComponent>(); behavior.DefaultTree = this.BakeTree(); }
public RepeaterUntilSuccessContinued(int maxIterations, BehaviorComponent behavior) { this.maxIterations = maxIterations; AssignBehaviors(new[] { behavior }); Name = "RepeaterContinued"; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
public void RegisterAgent(BehaviorComponent agent) { this.idleAgents.Add(agent); }
/// <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; }
/// <summary> /// returns a success even when the decorated component failed /// </summary> /// <param name="behavior">behavior to run</param> public Succeeder(BehaviorComponent behavior) { _Behavior = behavior; }
/// <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; }
/// <summary> /// executes the behavior every time again /// </summary> /// <param name="behavior">behavior to run</param> public Repeater(BehaviorComponent behavior) { _behavior = behavior; }
/// <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; }
public UntilSuccess(BehaviorComponent behavior) { AssignBehaviors(new[] { behavior }); Name = "RepeaterContinued"; }
public abstract void AddChild(BehaviorComponent behaviorComponent);
/// <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; }
public OnNotCalled(BehaviorComponent finalizer) { this.finalizer = finalizer; }
public override void addChild(BehaviorComponent child) { m_childBehavior = child; }