public override ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance) { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.READY; if (this.conditionFunction(behaviourTreeInstance).BooleanResult) { behaviourTreeInstance.nodeStateDict.ObserveReplace() .Where(p => p.Key == this.action.key) .Subscribe(p => NextState(p.NewValue, behaviourTreeInstance)); this.action.Execute(behaviourTreeInstance); } else { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.FAILURE; } return(new ExecutionResult(true)); }
void NextState(BehaviourTreeInstance.NodeState _state, BehaviourTreeInstance _instance) { if (_state == BehaviourTreeInstance.NodeState.SUCCESS) { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.SUCCESS; } else if (_state == BehaviourTreeInstance.NodeState.FAILURE) { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.FAILURE; } }
public override ExecutionResult Execute(BehaviourTreeInstance _instance) { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.READY; _instance.nodeStateDic.ObserveReplace() .Where(item => item.Key == actions.Current.key) .Subscribe(item => NextState(item.NewValue, _instance)); actions.MoveNext(); actions.Current.Execute(_instance); return(new ExecutionResult(true)); }
private ExecutionResult IsHpLessThan(BehaviourTreeInstance _instance) { var enemyHp = Random.Range(0, 10); if (enemyHp <= 4) { Debug.Log("敵のHPが4以下。チャンス。"); return(new ExecutionResult(true)); } Debug.Log("敵のHPが4より大きい。まだ慌てる時間じゃない。"); return(new ExecutionResult(false)); }
private ExecutionResult DetermineBuilding(BehaviourTreeInstance instance) { if (transform.position == obj.transform.position) { Debug.Log("やったね!"); IsAttackBuilding = false; return(new ExecutionResult(false)); } return(new ExecutionResult(true)); }
void NextState(BehaviourTreeInstance.NodeState state, BehaviourTreeInstance behaviourTreeInstance) { if (state == BehaviourTreeInstance.NodeState.SUCCESS) { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.SUCCESS; } else if (state == BehaviourTreeInstance.NodeState.FAILURE) { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.FAILURE; } }
private ExecutionResult RightMove(BehaviourTreeInstance instance) { IsWalk = true; //エージェントが現目標地点に近づいてきたら、 //次の目標地点を選択します if (!agent.pathPending && agent.remainingDistance < 2.0f) { GotoNextPoint(); } Debug.Log(agent.remainingDistance); return(new ExecutionResult(false)); }
private ExecutionResult AttackBuilding(BehaviourTreeInstance instance) { if (IsAttackBuilding) { Debug.Log("建物を攻撃する"); agent.destination = obj.transform.position; return(new ExecutionResult(true)); } else if (!IsAttackBuilding) { return(new ExecutionResult(false)); } return(new ExecutionResult(false)); }
public override ExecutionResult Execute(BehaviourTreeInstance _instance) { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.READY; var result = action(_instance); if (result.booleanResult) { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.SUCCESS; } else { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.FAILURE; } return(result); }
/// <summary> /// 実行処理 /// </summary> /// <param name="_instance">BehaviourTreeInstance</param> /// <returns>実行結果</returns> public override ExecutionResult Execute(BehaviourTreeInstance _instance) { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.READY; if (conditionFunction(_instance).booleanResult) { _instance.nodeStateDic.ObserveReplace() .Where(item => item.Key == action.key) .Subscribe(item => NextState(item.NewValue, _instance)); action.Execute(_instance); } else { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.FAILURE; } return(new ExecutionResult(true)); }
override public ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance) { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.READY; behaviourTreeInstance.nodeStateDict.ObserveReplace() .Where(p => p.Key == actions.Current.key) .Subscribe(p => NextState(p.NewValue, behaviourTreeInstance)); this.actions.MoveNext(); this.actions.Current.Execute(behaviourTreeInstance); return(new ExecutionResult(true)); }
void NextState(BehaviourTreeInstance.NodeState _state, BehaviourTreeInstance _instance) { if (_state == BehaviourTreeInstance.NodeState.FAILURE) { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.FAILURE; } else if (_state == BehaviourTreeInstance.NodeState.SUCCESS) { if (actions.MoveNext()) { actions.Current.Execute(_instance); } else { _instance.nodeStateDic[key] = BehaviourTreeInstance.NodeState.SUCCESS; } } }
override public ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance) { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.READY; var result = action(behaviourTreeInstance); if (result.BooleanResult) { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.SUCCESS; } else { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.FAILURE; } return(result); }
void Start() { var attackNode = new DecoratorNode(IsHpLessThan, new ActionNode(AttackEnemy)); var moveTowerNode = new SequencerNode(new BehaviourTreeBase[] { new ActionNode(MoveNearTower), new ActionNode(Wait) }); var rootNode = new SelectorNode(new BehaviourTreeBase[] { attackNode, moveTowerNode }); node = new BehaviourTreeInstance(rootNode); node.finishRP.Where(item => item != BehaviourTreeInstance.NodeState.READY) .Subscribe(item => ResetCoroutineStart()); node.Excute(); }
void NextState(BehaviourTreeInstance.NodeState state, BehaviourTreeInstance behaviourTreeInstance) { if (state == BehaviourTreeInstance.NodeState.FAILURE) { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.FAILURE; } else if (state == BehaviourTreeInstance.NodeState.SUCCESS) { if (this.actions.MoveNext()) { this.actions.Current.Execute(behaviourTreeInstance); } else { behaviourTreeInstance.nodeStateDict[this.key] = BehaviourTreeInstance.NodeState.SUCCESS; } } }
private ExecutionResult IsHpLessThan(BehaviourTreeInstance instance) { var playerhp = GetComponent <EnemyHpBarControl>().hp; if (IsAttack) { //anim.SetTrigger("Initimidate"); Debug.Log("プレイヤーを発見しちゃった"); return(new ExecutionResult(true)); } else if (playerhp <= 0) { Debug.Log("死んじゃった。"); //anim.SetTrigger("IsDie"); //return new ExecutionResult(false); } Debug.Log("プレイヤーを発見出来てない"); return(new ExecutionResult(false)); }
private ExecutionResult BuildingDiscover(BehaviourTreeInstance instance) { if (obj != null) { if (Physics.Linecast(transform.position, obj.transform.position, BoxLayer)) { //見える Debug.Log("建物発見"); IsAttackBuilding = true; return(new ExecutionResult(true)); } else { //見えない Debug.Log("何も発見できていないよー。"); IsAttackBuilding = false; return(new ExecutionResult(false)); } } return(new ExecutionResult(false)); }
private ExecutionResult PlayerDiscover(BehaviourTreeInstance instance) { float sqrDistanceToPlayer = Vector3.SqrMagnitude(transform.position - Player.position); if (Physics.Linecast(transform.position, target.transform.position, BoxLayer)) { //見えない Debug.Log("何も発見できていないよー。"); IsAttack = false; return(new ExecutionResult(false)); } else if (sqrDistanceToPlayer <= 300) { //見える Debug.Log("プレイヤーを発見"); IsAttack = true; return(new ExecutionResult(true)); } return(new ExecutionResult(false)); }
void CreateNodes() { var attackNode = new SequencerNode(new BehaviourTreeBase[] { new ActionNode(AttackEnemy) }); var BuildingAttack = new SequencerNode(new BehaviourTreeBase[] { new ActionNode(AttackBuilding) }); var PlayerAttack = new SequencerNode(new BehaviourTreeBase[] { attackNode }); var discover = new SelectorNode(new BehaviourTreeBase[] { new ActionNode(PlayerDiscover), new ActionNode(BuildingDiscover) }); var moveNode = new SelectorNode(new BehaviourTreeBase[] { new ActionNode(RightMove), discover }); var rootNode = new SelectorNode(new BehaviourTreeBase[] { BuildingAttack, PlayerAttack, moveNode } ); node = new BehaviourTreeInstance(rootNode); node.finishRP.Where(p => p != BehaviourTreeInstance.NodeState.READY).Subscribe(p => ResetCoroutineStart()); node.finishRP.Value = BehaviourTreeInstance.NodeState.READY; node.Excute(); }
private ExecutionResult AttackEnemy(BehaviourTreeInstance instance) { float t = 0; if (t < 1) { t += Time.deltaTime; } transform.rotation = Quaternion.Slerp(transform.rotation, Player.rotation, t); anim.SetBool("IsSliding", IsSliding); Debug.Log("敵を攻撃する"); if (IsAttack) { float sqrDistanceToPlayer = Vector3.SqrMagnitude(transform.position - Player.position); Debug.Log(sqrDistanceToPlayer); if (sqrDistanceToPlayer < ShortSqrDistance) { IsSliding = true; IsWalk = false; } agent.destination = target.transform.position; return(new ExecutionResult(true)); } else if (!IsAttack) { return(new ExecutionResult(false)); } return(new ExecutionResult(false)); }
private ExecutionResult AttackEnemy(BehaviourTreeInstance _instance) { Debug.Log("敵を攻撃する"); return(new ExecutionResult(true)); }
private ExecutionResult MoveNearTower(BehaviourTreeInstance instance) { Debug.Log("一番近くのタワーにいく。"); return(new ExecutionResult(true)); }
private ExecutionResult Wait(BehaviourTreeInstance instance) { Debug.Log("待機。"); return(new ExecutionResult(true)); }
public abstract ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance);
private ExecutionResult LeftMove(BehaviourTreeInstance instance) { transform.position += Vector3.left * speed * Time.deltaTime; return(new ExecutionResult(true)); }