public static BT_Result TickChild(BT_Node child, BT_AgentMemory am) { if (child.CheckPrecondition(am) == false) { return(BT_Result.FAILURE); } am.FinalNodeLastCall = child.ID; if (child.Activates == false) { // Debug.Log(child.ID + " - " + child.GetType().ToString() + " - decider tick"); BT_Result result = child.Tick(am); return(result); } else { am.ActivateNode(child.ID); // Debug.Log(child.ID + " - " + child.GetType().ToString() + " - action tick"); BT_Result result = child.Tick(am); if (result != BT_Result.RUNNING) { am.DeactivateNode(child.ID); } return(result); } }
public override IEnumerator Executar() { state = BT_State.RUNNING; for (int i = 0; i < transform.childCount; i++) { BT_Node node = transform.GetChild(i).GetComponent <BT_Node> (); node.state = BT_State.RUNNING; node.StartCoroutine("Executar"); while (node.state == BT_State.RUNNING) { yield return(null); } if (node.state == BT_State.FAILURE) { this.state = BT_State.FAILURE; this.StopCoroutine("Executar"); break; } } if (this.state != BT_State.FAILURE) { this.state = BT_State.SUCCESS; } }
public void AddChild(BT_Node <T> child) { if (CanAddChild()) { childs.Add(child); } }
public void AddChild(BT_Node <T> child) { if (CanAddChild(child)) { child.Blackboard = this.Blackboard; children.Add(child); } }
public void SetChild(BT_Node <T> child) { if (CanAddChild(child)) { this.child = child; this.child.Blackboard = this.Blackboard; } }
public BT_Result Tick(BT_AgentMemory am) { am.ResetActiveNodesList(); am.ProcessTimers(am.DeltaTime); am.CurrentTree = this; BT_Result result = BT_Node.TickChild(Root, am); // Debug.Log(am.Character.Name + " - " + am.FinalNodeLastCall + " - " + GetNodeByID(am.FinalNodeLastCall).GetType()); return(result); }
public void Configurar() { BT_Node nodo = GetComponent <BT_Node> (); if (nodo.GetType() == typeof(BT_Selector)) { texto.text = "?"; } else if (nodo.GetType() == typeof(BT_Sequence)) { texto.text = ">"; } }
public Timing(BT_Node node) { target = node; isActivated = false; }
public virtual bool CanAddChild(BT_Node <T> child) { return(true); }
public FrameCounter(BT_Node node, int _waitCount) : base(node) { currentFrameCount = 0; waitCount = _waitCount; }
public BT_Node Add(BT_Node node) { Children.Add(node); return(node); }
public bool SetNewDestination(Tile tile, bool startMovement, IAccessible tileOwner, BT_Node callingNode) { #if UNITY_EDITOR CharacterLogEntry newLog = new CharacterLogEntry(Time.time, tile, tileOwner, callingNode); #endif if (State == CharacterState.PreparingForDeletion || State == CharacterState.UsingService) { return(false); } if (tile == null || inaccessibleTilesTimers.ContainsKey(tile) || tile.MovementCost == 0f) { DestinationTile = CurrentTile; return(false); } if (tile == DestinationTile) { if (startMovement) { State = CharacterState.Movement; } #if UNITY_EDITOR log.Add(newLog); #endif return(true); } DestinationTile = tile; if (Path != null && Path.Goal != tile) { NextTile = null; MovementPercentage = 0f; Path = null; } State = startMovement ? CharacterState.Movement : CharacterState.PreparingForCheckingPath; #if UNITY_EDITOR log.Add(newLog); #endif return(true); }
public CharacterLogEntry(float time, Tile goalTile, IAccessible tileOwner, BT_Node callingNode) { Time = time; GoalTile = goalTile; TileOwner = tileOwner; CallingNode = callingNode; }
public BT_RepeatUntilFail(BT_Node child) : base(child) { }
public void AddChildNode(BT_Node node) { childNode = node; }
public BT_DecoratorNode(BT_Node child) { Child = child; }
public BT_Inverter(BT_Node child) : base(child) { }
public override bool CanAddChild(BT_Node <T> child) { return(child is BT_ConditionNode <T> || child is BT_DecoratorNot <T>); }
public void AddChildNode(BT_Node node) { childNodeList.Add(node); }
public void LoadHumanTree() { float waitBeforeEntering = 0.2f; Root = Subtree(new BT_Priority(), new BT_IsUsingService(), new BT_RemoveWorkplaceIfCannotReserve(), new BT_GoToRandomTile(), Subtree(new BT_Sequence(), new BT_HasReservation(), new BT_Inverter(new BT_AreReservedStoragesAccessible()), new BT_RemoveReservation() ), Subtree(new BT_MemSequence(), new BT_HasReservation(), new BT_HasResourceForReservation(), new BT_GoToTargetStorage(), new BT_Wait(waitBeforeEntering), new BT_DepositResource() ), Subtree(new BT_MemSequence(), new BT_HasReservation(), new BT_GoToSourceStorage(), new BT_Wait(waitBeforeEntering), new BT_TakeResource() ), Subtree(new BT_Sequence(), new BT_HasResource(), new BT_Inverter(new BT_HasReservation()), new BT_FindNewStorageForResource() ), Subtree(new BT_MemSequence(), new BT_HasService(), new BT_GoToService(), new BT_Wait(waitBeforeEntering), new BT_StartUsingService() ), Subtree(new BT_Sequence(), new BT_IsNeedHigherThan("Health", StaticData.NeedLevelToDie), new BT_Die() ), Subtree(new BT_Sequence(), new BT_IsNeedHigherThan("Health", StaticData.NeedLevelToSeekService), new BT_FindService("Health") ), Subtree(new BT_Sequence(), new BT_IsNeedHigherThan("Hunger", StaticData.NeedLevelToDie), new BT_Die() ), Subtree(new BT_Sequence(), new BT_IsNeedHigherThan("Hunger", StaticData.NeedLevelToSeekService), new BT_FindService("Hunger") ), Subtree(new BT_MemSequence(), new BT_HasWorkplace(), new BT_GoToWorkplace(), new BT_Wait(waitBeforeEntering), new BT_Work() ), Subtree(new BT_Sequence(), new BT_Inverter(new BT_HasWorkplace()), new BT_FindTransportJob() ), Subtree(new BT_Sequence(), new BT_Inverter(new BT_HasReservation()), new BT_FindWorkplace() ), new BT_SetRandomTile() ); AssignIDs(); }