private void Update() { GlobalSearchCache.Update(); if (!_isSearching) { return; } if (_blocks.Count == 0 && !_hasPoint) { _isSearching = false; Message("OnFinishSearch"); } if (DebugPoints) { foreach (var block in _blocks) { debugBlock(block); } foreach (var block in _investigatedBlocks) { debugBlock(block); } } if (_block.Empty && !_hasPoint && _blocks.Count > 0) { var pickedIndex = -1; var previousValue = 0f; for (int i = 0; i < _blocks.Count; i++) { var vector = _searchPosition - _blocks[i].Center; var distance = vector.magnitude; var direction = vector / distance; var value = distance; if (_hasBlockDirection) { value *= -Vector3.Dot(direction, _blockDirection) * 0.5f + 1.5f; } else { value *= -Vector3.Dot(direction, _actor.HeadDirection) * 0.5f + 1.5f; } if (pickedIndex < 0 || value < previousValue) { pickedIndex = i; previousValue = value; } } _block = _blocks[pickedIndex]; _blocks.RemoveAt(pickedIndex); _investigatedBlocks.Add(_block); _hasBlockDirection = true; _blockDirection = (_block.Center - _searchPosition).normalized; } if (!_hasPoint) { int index; float value; if (findBestPoint(_block, out index, out value)) { setPoint(_block.Indices[index]); _block.Investigate(index); } } if (!_hasPoint) { return; } if (!_hasApproached && !shouldApproach(_point)) { _hasApproached = true; if (_wasRunning) { run(); } else { walk(); } } if (_wasRunning && !shouldRunTo(_point.Position)) { walk(); } _checkWait -= Time.deltaTime; if (_checkWait <= float.Epsilon) { glimpse(_block); for (int b = _blocks.Count - 1; b >= 0; b--) { glimpse(_blocks[b]); if (_blocks[b].Empty) { _investigatedBlocks.Add(_blocks[b]); _blocks.RemoveAt(b); } } _checkWait = 0.25f; } if (DebugTarget) { Debug.DrawLine(transform.position, _point.Position, Color.yellow); } if (canBeInvestigated(_point)) { finishInvestigatingThePoint(); } }
private void OnLevelWasLoaded(int level) { GlobalSearchCache.Restart(); }