}//OnStateEnter public override bool Action() { base.Action(); if (Time.timeSinceLevelLoad - this.enteredTime < 1f) { AICtrl.MvmntCmp.SetVelocity(Vector2.zero); return false; } if (bIsAtTarget) return false; if (this.target == null) { this.target = _wpCtrl.GetNext().transform; } bool hasArrived = this.GoToTarget(this.target); if (hasArrived) { bIsAtTarget = _wpCtrl.IsAtLastPoint(); this.target = _wpCtrl.GetNext().transform; } if (bIsAtTarget) { _wpCtrl.ResetPatrolPoints(); AICtrl.OnLookAround(this.BackToPatrol); } return true; }//Action
public override bool Action() { AICtrl.MvmntCmp.SetVelocityX(0); if (!bIsAttacking) { AICtrl.StartCoroutine(ChargedAttack()); } return false; }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter(animator, stateInfo, layerIndex); if (_pathFinder == null) _pathFinder = AICtrl.GetComponent<Pathfinder>(); if(_input == null) _input = AICtrl.ControlledBy.GetComponent<InputManager>(); #if UNITY_EDITOR if (_pathFinder == null) Debug.LogError("No PathFinder in AIController object!"); #endif if (AICtrl.StateMachineAnimator.GetBool("IsDead")) Interrupt(); if (!bHasInit && _wpCtrl == null) { _wpCtrl = AICtrl.GetComponent<WaypointControl>(); bHasInit = true; } _wpCtrl.EOnPointReached -= this.OnPointReached; _wpCtrl.EOnFirstPointReached -= this.OnFirstPointReached; _wpCtrl.EOnLastPointReached -= this.OnLastPointReached; _wpCtrl.EOnPointReached += this.OnPointReached; _wpCtrl.EOnFirstPointReached += this.OnFirstPointReached; _wpCtrl.EOnLastPointReached += this.OnLastPointReached; AICtrl.LadderClimberCmp.EOnLadderUnset -= OffTheLadder; AICtrl.LadderClimberCmp.EOnLadderUnset += OffTheLadder; }//OnStateEnter
protected void finish(AICtrl agent, State stat) { this.state = stat; if (this.parent != null) { this.parent.tryMoveNext(agent, stat); } }
protected override bool checkState(AICtrl agent, State stat) { if (stat == BTNode.State.FINISH) { finish(agent, State.FINISH); return(false); } return(true); }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter(animator, stateInfo, layerIndex); if (_pathFinder == null) _pathFinder = AICtrl.GetComponent<Pathfinder>(); #if UNITY_EDITOR if (_pathFinder == null) Debug.LogError("No PathFinder in AIController object!"); #endif }//OnStateEnter
// Use this for initialization void Start() { // Component References BlkBrdMngr = GetComponent<BlkBrdMngr>(); AICtrl = GetComponent<AICtrl>(); // Starting Conditions CanJump = true; JumpWaitTime = 0.5f; }
public sealed override void execute(AICtrl agent) { if (_isFirstExe) { _isFirstExe = false; beforFirstExecute(agent); } iterChild = childs.GetEnumerator(); moveNext(agent); }
public override void PendingCheck(AICtrl agent) { for (int i = 0; i < childs.Count; i++) { BTNode child = childs [i]; if (child.state == BTNode.State.PENDING) { child.PendingCheck(agent); break; } } }
public sealed override void execute(AICtrl agent) { bool conditionPass = condition(agent); if (conditionPass == isTrue) { finish(agent, State.FINISH); } else { finish(agent, State.FAIL); } }
protected void moveNext(AICtrl agent) { if (iterChild.MoveNext()) { var currentChild = iterChild.Current; currentChild.state = BTNode.State.PENDING; checkPendingSole(currentChild); currentChild.execute(agent); } else { moveEnd(agent); } }
public void tryMoveNext(AICtrl agent, State stat) { bool pass = checkState(agent, stat); if (pass) { if (agent.enabled) { moveNext(agent); } else { this.finish(agent, State.FAIL); } } }
protected void delayFinish(AICtrl agent, State stat) { Action a = () => { this.state = stat; Action b = () => { if (this.parent != null) { this.parent.tryMoveNext(agent, stat); } }; TimerMng.Add(Delay, b); }; TimerMng.Add(Delay, a); }
}//Action public virtual bool GoToTarget(Transform target) { float direction = AICtrl.DirSwitcherCmp.Direction; Vector2 distanceVector = (target.position - AICtrl.transform.position); //float distance = distanceVector.magnitude; float distance = Vector2.Distance(AICtrl.transform.position, target.position); if (!AICtrl.IsLookingAtTarget(target) && distance >= AICtrl.MvmntCmp.Velocity.x) { AICtrl.DirSwitcherCmp.OnSwitchDirection(); direction = AICtrl.DirSwitcherCmp.Direction; } Vector2 deltaMovement = Vector2.right * AICtrl.MvmntCmp.RunSpeed * direction; var box = AICtrl.ControlledBy.ColliderCmp as BoxCollider2D; var size = box.size; Debug.DrawRay(AICtrl.transform.position, Vector2.down * (Mathf.Abs(deltaMovement.y) + size.y / 2), Color.green); Debug.DrawRay(AICtrl.transform.position, Vector2.right * (Mathf.Abs(deltaMovement.x)), Color.green); bool isAtX = Mathf.Abs(distanceVector.x) <= Mathf.Abs(deltaMovement.x); bool isAtY = false; if (distanceVector.y <= 0) isAtY = Mathf.Abs(distanceVector.y) <= Mathf.Abs(deltaMovement.y) + size.y / 2; if (AICtrl.LadderClimberCmp.IsClimbing) isAtY = false; if (isAtX && !isAtY) UseLadder(ref deltaMovement, Mathf.Sign(distanceVector.normalized.y)); //Debug.Log(distanceVector.y + " : " + target.position.y + " -> " + isAtY + " : " + deltaMovement.y); AICtrl.MvmntCmp.SetVelocity(deltaMovement); bool hasArrived = isAtX && isAtY; return hasArrived; }//GoToTarget
protected override void moveEnd(AICtrl agent) { finish(agent, State.FAIL); }
public virtual void PendingCheck(AICtrl agent) { }
public void UpdateTransform(int id) { GameObject unit = GameMgr.Instance.GetObjectWithID(id); int dir; int pos_r, pos_c; float pos_z, pos_y, pos_x;; float angle; if (id == 1 || id == 3) //만약 플레이어라면 { PlayerCtrl playerctrl = unit.GetComponent <PlayerCtrl>(); dir = playerctrl.GetDirection(); pos_r = playerctrl.pos.R; pos_c = playerctrl.pos.C; } else //인공지능이라면 { AICtrl aictrl = unit.GetComponent <AICtrl>(); dir = aictrl.GetDirection(); pos_r = aictrl.pos.R; pos_c = aictrl.pos.C; } pos_z = 14.5f - pos_r; pos_x = -14.5f + pos_c; pos_y = 0.3f; switch (dir) { case 0: angle = 180; break; case 1: angle = 270; break; case 2: angle = 0; break; case 3: angle = 90; break; default: angle = 0; break; } unit.transform.position = new Vector3(pos_x, pos_y, pos_z); unit.transform.eulerAngles = new Vector3(0, angle, 0); }
public virtual void execute(AICtrl agent) { }
public override void execute(AICtrl agent) { finish(agent, State.PENDING); }
public virtual bool condition(AICtrl agent) { return(false); }
protected virtual void beforFirstExecute(AICtrl agent) { }
// Use this for initialization void Start() { // Component References BlkBrdMngr = GetComponent<BlkBrdMngr>(); AICtrl = GetComponent<AICtrl>(); // Starting Conditions MovingToOtherSide = false; }
protected virtual void moveEnd(AICtrl agent) { }
protected virtual bool checkState(AICtrl agent, State stat) { return(false); }
public void Attack(AICtrl enemy) { m_actionCtrl.OverAction(); enemy.Hit(attackDamage); MapMgr.Instance.HideAttackableItem(); }
public override void PendingCheck(AICtrl agent) { }