private IEnumerator ContinueFinding(Transform target, Action <bool?> pathFinded) { seeker.CancelCurrentPathRequest(); continueFinding = true; while (continueFinding) { yield return(MyFindPath(target.transform.position, pathFinded)); } }
private void OnMouseUp() { #if UNITY_EDITOR seeker.CancelCurrentPathRequest(); ControllManager.instance.moveProducableObject = gameObject; MainCanvasController.instance.CloseInfoPanel(); spriteRenderer.color = Color.red; AstarPath.active.Scan(); // update path area #else MouseDownPhone(); #endif }
public void Dispose() { LastRepath = float.NegativeInfinity; Seeker.CancelCurrentPathRequest(); Agent.enabled = false; Agent = null; }
public void SetDestination(Vector2 dest) { //Cancel path if existing if (seeker.GetCurrentPath() != null) { seeker.CancelCurrentPathRequest(); } if (target != null) { target = null; } if (oldTarget != null) { oldTarget = null; } this.oldDestination = this.destination; this.destination = dest; if (this.destination != this.oldDestination) { atDestination = false; canMove = true; } InvokeRepeating("UpdatePath", 0f, 0.5f); }
public virtual void Stop(bool gameOver = false) { _stop = true; Seeker.CancelCurrentPathRequest(true); CancelInvoke(nameof(UpdatePath)); StopCoroutine(nameof(ApplySanity)); int dice = Random.Range(1, 20); if (cloudPrefab && !gameOver) { var cloud = Instantiate(cloudPrefab.GetComponent <CloudBehaviour>(), transform.position, Quaternion.identity); if (dieSounds.Length != 0) { cloud.PlaySound(dieSounds[Random.Range(0, dieSounds.Length)]); } } if (sanityPickupPrefab && dice == 1) { Instantiate(sanityPickupPrefab, transform.position, Quaternion.identity); } EnemyTracker.RemoveEnemy(currentWaveIndex); }
public void OnRightClick(Vector2 mousePosition) { var hit = Physics2D.Raycast((Vector3)mousePosition + Vector3.back, Vector3.forward, 2, layerMask); if (hit.collider == null) { myTarget = null; } else { myTarget = hit.collider.gameObject; } mySeeker.CancelCurrentPathRequest(); mySeeker.StartPath(transform.position, mousePosition, path => { if (path.error) { Debug.Log(path.errorLog, this); return; } myPath = path; myCurrentWaypoint = 0; }); }
public void StopFollowingPlayer() { CancelInvoke("UpdatePath"); seeker.CancelCurrentPathRequest(); path = null; }
/// <summary> /// 停止自动寻路 /// </summary> public void StopAutoMove() { if (aiSeeker != null) { aiSeeker.CancelCurrentPathRequest(); } InitAIPath(); }
/// <summary> /// Clears the current path of the agent. /// /// Usually invoked using <see cref="SetPath(null)"/> /// /// See: <see cref="SetPath"/> /// See: <see cref="isStopped"/> /// </summary> protected virtual void ClearPath() { // Abort any calculations in progress if (seeker != null) { seeker.CancelCurrentPathRequest(); } canSearchAgain = true; reachedEndOfPath = false; // Release current path so that it can be pooled if (path != null) { path.Release(this); } path = null; interpolator.SetPath(null); }
public void setTarget(Vector3 location) { waypoint = location; myPathIndex = 0; myPath = null; if (seekr) { seekr.CancelCurrentPathRequest(); seekr.StartPath(transform.position, (Vector3)waypoint); } }
void OnDisable() { seeker.CancelCurrentPathRequest(); // Release current path so that it can be pooled if (path != null) { path.Release(this); } path = null; seeker.pathCallback -= OnPathComplete; }
public void OnDisable () { // Abort any calculations in progress if (seeker != null) seeker.CancelCurrentPathRequest(); canSearchAgain = true; // Release the current path so that it can be pooled if (path != null) path.Release(this); path = null; // Make sure we no longer receive callbacks when paths complete seeker.pathCallback -= OnPathComplete; }
public override void OnStateQuit(State nextState) { base.OnStateQuit(nextState); rigidbody.velocity = Vector2.zero; indexLastPatrolPoint = indexTargetPatrolPoint; seeker?.CancelCurrentPathRequest(); }
private void ClearPath() { // Abort any calculations in progress if (seeker != null) { seeker.CancelCurrentPathRequest(); } canMove = false; atDestination = true; reachedEndOfPath = false; // Release current path so that it can be pooled /*if (path != null) path.Release(this);*/ path = null; }
public void SetTarget(Transform t) { //Cancel path if existing if (seeker.GetCurrentPath() != null) { seeker.CancelCurrentPathRequest(); } //destination = nullVector; //oldDestination = nullVector; this.oldTarget = this.target; this.target = t; if (this.target != this.oldTarget) { //Debug.Log("test"); atDestination = false; canMove = true; } CancelInvoke("UpdatePath"); InvokeRepeating("UpdatePath", 0f, 0.5f); }
internal void Stop() { seeker.CancelCurrentPathRequest(); }
public void CancelLastPath() { seeker.CancelCurrentPathRequest(); }
private void CancelCurrentPathRequest() { _waitingForPathCalculation = false; _seeker.CancelCurrentPathRequest(); }
void SpringBehaviour() { if (_greenMobs.Length >= _locationGenerator.Size * 1.5) { _timeToBreeding = 20f; } if (_timeToBreeding > 0f) { _timeToBreeding = _timeToBreeding - Time.deltaTime; } else { _timeToBreeding = 0; } if (_way == WayPoint.Going) { if (_timeToBreeding <= 0f) { foreach (var t in _greenMobs) { if (Math.Abs(t.transform.position.x - gameObject.transform.position.x) < 4f && Math.Abs(t.transform.position.y - gameObject.transform.position.y) < 4f) { if (_foodNeeds.ReturnFood() > 50 && _waterNeeds.ReturnWater() > 50) { _way = WayPoint.Breeding; } } } } if (gameObject.transform.position.x > _target.x - 0.5f && gameObject.transform.position.x <= _target.x + 0.5f && gameObject.transform.position.y > _target.y - 0.5f && gameObject.transform.position.y <= _target.y + 2.7f) { _way = WayPoint.Choose; } } if (_way == WayPoint.Choose) { if (_timeManager.NameOfTime == TimeManager.TimeName.Night) { _seeker.CancelCurrentPathRequest(); } else { if (_waterNeeds.ReturnWater() < _foodNeeds.ReturnFood()) { _way = _waterNeeds.ReturnWater() < 85 ? WayPoint.Water : WayPoint.Walking; } else { _way = _foodNeeds.ReturnFood() < 85 ? WayPoint.Food : WayPoint.Walking; } } } if (_way == WayPoint.Breeding) { _timeToBreeding = 15f; Instantiate(GreenMobPrefab, new Vector3(gameObject.transform.position.x + 0.3f, gameObject.transform.position.y + 0.3f, gameObject.transform.position.z), Quaternion.identity); _way = WayPoint.Going; } if (_way == WayPoint.Food) { int number = 0; var distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); for (int i = 0; i < _foods.Length; i++) { var need = _foods[i].GetComponent <FoodHave>(); if (need.ReturnFood() > _foodNeeds.ReturnFoodNeeds()) { if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y + _locationGenerator.HeightOfGrassBlock / 2)) < distance) { number = i; distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); } } } _target = _foods[number].transform.position; _seeker.StartPath(transform.position, _target + new Vector3(0f, 1.7f, 0), OnPathComplete); _way = WayPoint.Going; } if (_way == WayPoint.Water) { int number = 0; var distance = (Math.Abs(_waters[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_waters[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); for (int i = 0; i < _waters.Length; i++) { var need = _waters[i].GetComponent <WaterHave>(); if (need.ReturnWater() > _waterNeeds.ReturnWaterNeed()) { if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y + _locationGenerator.HeightOfGrassBlock / 2)) < distance) { number = i; distance = (Math.Abs(_waters[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_waters[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); } } } _target = _waters[number].transform.position; _seeker.StartPath(transform.position, _target + new Vector3(0f, 2.5f, 0), OnPathComplete); _way = WayPoint.Going; } if (_way == WayPoint.Walking) { _goingTarget = new Vector3( _locationGenerator.Size * _locationGenerator.Rand.Next(0, (int)_locationGenerator.LongOfGrassBlock * 9 / 10), -_locationGenerator.Size * _locationGenerator.Rand.Next(0, (int)_locationGenerator.HeightOfGrassBlock / 2), 0f); _target = _goingTarget; _seeker.StartPath(transform.position, _target, OnPathComplete); _way = WayPoint.Going; } }
void Way() { if (_way == WayPoint.Going) { if (_timeToBreeding <= 0f) { for (int i = 0; i < _redMobs.Length; i++) { if (Math.Abs(_redMobs[i].transform.position.x - gameObject.transform.position.x) < 4f && Math.Abs(_redMobs[i].transform.position.y - gameObject.transform.position.y) < 4f) { if (_foodNeeds.ReturnFood() > 85) { if (_waterNeeds.ReturnWater() > 85) { _way = WayPoint.Breeding; } } } } } for (int i = 0; i < _greenMobs.Length; i++) { if (Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x) < 4f && Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y) < 4f) { _way = WayPoint.Devouring; } } if (gameObject.transform.position.x > _target.x - 0.5f && gameObject.transform.position.x <= _target.x + 0.5f && gameObject.transform.position.y > _target.y - 0.5f && gameObject.transform.position.y <= _target.y + 2.7f) { //print("Done!"); _way = WayPoint.Choose; } } if (_way == WayPoint.Breeding) { _timeToBreeding = 15f; Instantiate(RedMobPrefab, new Vector3(gameObject.transform.position.x + 0.3f, gameObject.transform.position.y + 0.3f, gameObject.transform.position.z), Quaternion.identity); _way = WayPoint.Going; } if (_way == WayPoint.Devouring) { if (_timeManager.NowSeason == TimeManager.Season.Summer & _waterNeeds.ReturnWater() < 75f & _foodNeeds.ReturnFood() < 75f) { for (int i = 0; i < _greenMobs.Length; i++) { if (Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x) < 4f && Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y) < 4f) { //print("OM NOM NOM!!!"); Destroy(_greenMobs[i]); } } _waterNeeds.AddWater(100f); _foodNeeds.AddFood(100f); } if (_waterNeeds.ReturnWater() < 60f || _foodNeeds.ReturnFood() < 60f) { for (int i = 0; i < _greenMobs.Length; i++) { if (Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x) < 4f && Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y) < 4f) { //print("OM NOM NOM!!!"); Destroy(_greenMobs[i]); } } _waterNeeds.AddWater(100f); _foodNeeds.AddFood(100f); } _way = WayPoint.Going; } if (_way == WayPoint.Food) { if (_timeManager.NowSeason == TimeManager.Season.Summer) { int number = 0; if (_greenMobs.Length > 0) { float distance = (Math.Abs(_greenMobs[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_greenMobs[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); for (int i = 0; i < _greenMobs.Length; i++) { if ((Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y + _locationGenerator.HeightOfGrassBlock / 2)) < distance) { number = i; distance = (Math.Abs(_greenMobs[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_greenMobs[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); } } _target = _greenMobs[number].transform.position; _seeker.StartPath(transform.position, _target + new Vector3(0f, 1.7f, 0), OnPathComplete); _way = WayPoint.Going; } else { var distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); for (int i = 0; i < _foods.Length; i++) { var need = _foods[i].GetComponent <FoodHave>(); if (need.ReturnFood() > _foodNeeds.ReturnFoodNeeds()) { if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y + _locationGenerator.HeightOfGrassBlock / 2)) < distance) { number = i; distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); } } } _target = _foods[number].transform.position; _seeker.StartPath(transform.position, _target + new Vector3(0f, 1.7f, 0), OnPathComplete); _way = WayPoint.Going; } } else { int number = 0; var distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); for (int i = 0; i < _foods.Length; i++) { var need = _foods[i].GetComponent <FoodHave>(); if (need.ReturnFood() > _foodNeeds.ReturnFoodNeeds()) { if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y + _locationGenerator.HeightOfGrassBlock / 2)) < distance) { number = i; distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); } } } _target = _foods[number].transform.position; _seeker.StartPath(transform.position, _target + new Vector3(0f, 1.7f, 0), OnPathComplete); _way = WayPoint.Going; } } if (_way == WayPoint.Water) { //print("water"); WaterHave need; int number = 0; //WaterNeeds waterNeeds = GetComponent<WaterNeeds>(); float distance; distance = (Math.Abs(_waters[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_waters[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); for (int i = 0; i < _waters.Length; i++) { need = _waters[i].GetComponent <WaterHave>(); if (need.ReturnWater() > _waterNeeds.ReturnWaterNeed()) { if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y + _locationGenerator.HeightOfGrassBlock / 2)) < distance) { number = i; distance = (Math.Abs(_waters[number].transform.position.x - gameObject.transform.position.x - _locationGenerator.LongOfGrassBlock / 2) + Math.Abs(_waters[number].transform.position.y - gameObject.transform.position.y + _locationGenerator.LongOfGrassBlock / 2)); } } } _target = _waters[number].transform.position; _seeker.StartPath(transform.position, _target + new Vector3(0f, 2.5f, 0), OnPathComplete); _way = WayPoint.Going; } if (_way == WayPoint.Walking) { var seeker = GetComponent <Seeker>(); _goingTarget = new Vector3( _locationGenerator.Size * _locationGenerator.Rand.Next(0, (int)_locationGenerator.LongOfGrassBlock * 9 / 10), -_locationGenerator.Size * _locationGenerator.Rand.Next(0, (int)_locationGenerator.HeightOfGrassBlock / 2), 0f); _target = _goingTarget; // _target = GameObject.Find("Player").transform.position; seeker.StartPath(transform.position, _target, OnPathComplete); _way = WayPoint.Going; } if (_way == WayPoint.Choose) { if (_timeManager.NameOfTime == TimeManager.TimeName.Morning) { _seeker.CancelCurrentPathRequest(); } else { WaterNeeds water = GetComponent <WaterNeeds>(); FoodNeeds food = GetComponent <FoodNeeds>(); if (water.ReturnWater() < food.ReturnFood()) { if (water.ReturnWater() < 85) { _way = WayPoint.Water; } else { _way = WayPoint.Walking; ; } } else { if (food.ReturnFood() < 85) { _way = WayPoint.Food; } else { _way = WayPoint.Walking; } } } } }