void FixedUpdate() { lineOfSight.enabled = _config.lightIsOn; lineOfSight.SetStatus(LineOfSight.Status.Idle); if (lineOfSight.enabled) { if (lineOfSight.SeeByTag("Player")) { List <GameObject> obs = lineOfSight.getViewing(); GameObject obj = obs[0]; Player player = obj.GetComponent <Player>(); if (player != null) { if (!player.disguised) { Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, alertRadious); GameObject nearest = null; float nearestDist = 0f; foreach (Collider c in colliders) { if (c.tag.Equals("Soldier")) { float dist = Vector3.Distance(c.gameObject.transform.position, transform.position); if (nearest == null || dist < nearestDist) { nearestDist = dist; nearest = c.gameObject; } } } if (nearest != null) { FSMManager g = nearest.GetComponent <FSMManager>(); BasicObjectAttr attr = nearest.GetComponent <BasicObjectAttr>(); // We arrive to destination List <SearchConfig> searchConf = g.GetBasicState().GetSearchConfig(); foreach (SearchConfig sc in searchConf) { if (sc.doWhenAlert != null) { IAState st = sc.doWhenAlert.Invoke(obj); g.setCurrentState(st); } } } lineOfSight.SetStatus(LineOfSight.Status.Alerted); } else { lineOfSight.SetStatus(LineOfSight.Status.Suspicious); } } } } }
public IAState setTarget(GameObject target) { if (target != null) { this.target = target; this.targetCtrl = target.GetComponent <CharacterController>(); this.targetAttr = target.GetComponent <BasicObjectAttr>(); } return(this); }
/** * Executed when state starts * @param obj */ public virtual void start(GameObject obj) { this.from = obj; this.fromCtrl = obj.GetComponent <CharacterController>(); this.fromAttr = obj.GetComponent <BasicObjectAttr>(); this.animatorController = obj.GetComponent <SoldierAnimatorController>(); if (this.fromAttr == null || this.fromCtrl == null) { throw new ExecutionEngineException("All characters must have a character controller and character attributes"); } }
void Start() { fromAttr = GetComponent <BasicObjectAttr>(); this.originalPos.transform.parent = null; FSMManager manager = GetComponent <FSMManager>(); NavMeshAgent agent = GetComponent <NavMeshAgent>(); RandomState search = new RandomState(); FollowState follow = new FollowState(); IdleState idle = new IdleState(); idle.isInfinite = true; InvestigateState investigateState = new InvestigateState(); manager.GetBasicState().configure("Player", (o) => { return(null); }, (o) => { investigateState.setTargetPos(o.transform.position); investigateState.SetDoWhenArrive((s) => { Collider[] coll = Physics.OverlapSphere(gameObject.transform.position, fromAttr.dangerViewAreaRadius); Debug.Log("Clll" + coll.Length); foreach (Collider c in coll) { if (c.tag.Equals("Player")) { var go = Camera.main.GetComponent <GameOverCameraControl>(); go.showDeadEffect = true; return(null); } } idle.time = fromAttr.investigateWaitTime; idle.isInfinite = false; idle.onComplete((s1) => { investigateState.setTargetPos(this.originalPos.transform.position); investigateState.SetDoWhenArrive((s2) => { idle.isInfinite = true; transform.rotation = this.originalPos.transform.rotation; agent.destination = this.transform.position; return(idle); }); return(investigateState); }); return(idle); }); return(investigateState); }); manager.setCurrentState(idle); }
void Start() { fromAttr = GetComponent <BasicObjectAttr>(); FSMManager manager = GetComponent <FSMManager>(); RandomState search = new RandomState(); FollowState follow = new FollowState(); IdleState idle = new IdleState(); PatrolState patrol = new PatrolState(); InvestigateState investigateState = new InvestigateState(); patrol.patrolRoute = patrolRoute; patrol.setAgent(GetComponent <NavMeshAgent>()); manager.GetBasicState().configure("Player", (o) => { investigateState.setTargetPos(o.transform.position).SetDoWhenArrive(null); return(investigateState); }, (o) => { investigateState.setTargetPos(o.transform.position); investigateState.SetDoWhenArrive((s) => { Collider[] coll = Physics.OverlapSphere(gameObject.transform.position, fromAttr.dangerViewAreaRadius); foreach (Collider c in coll) { if (c.tag.Equals("Player")) { var go = Camera.main.GetComponent <GameOverCameraControl>(); go.showDeadEffect = true; return(null); } } return(patrol); }); return(investigateState); }); manager.setCurrentState(patrol); }
void Awake() { basicState = new BasicState(this); basicState.start(this.gameObject); attributes = GetComponent <BasicObjectAttr>(); }