// checks whether a given target is seen and updates their detection values accordingly private void ProcessDetectedTargetEntry(DetectedTarget entry) { entry.DetectedThisFrame = Scan(entry.Target, _unit.MoveController.Body.transform, _visionRange, _visionLayers, _visionAngle); entry.DetectionValue += entry.DetectedThisFrame ? Time.deltaTime : -Time.deltaTime; if (entry.DetectionValue > MaxDetection) { entry.DetectionValue = MaxDetection; } }
private void DetectionThresholdHit(DetectedTarget entry) { CurrentDetectable = entry; HighestDetectedTarget = null; CurrentDetectable.DetectionValue = MaxDetection; Unit unit = entry.Target as Unit; if (unit != null) { OverrideCurrentTarget(unit); } _detectedTargets.Clear(); }
private void SetDetectionDisplayValue() { bool showDisplay = false; if (_targetManager.CurrentDetectable != null) { _fillBar.gameObject.SetActive(showDisplay); return; } DetectedTarget highest = _targetManager.HighestDetectedTarget; showDisplay = highest != null && highest.DetectionValue > 0f; _fillBar.gameObject.SetActive(showDisplay); if (!showDisplay) { return; } float value = highest.DetectionValue / NPCTargetManager.DetectionThreshold; _fillBar.UpdateValueInstant(value); }
private void ProcessDetectedTargets() { // if there is a current focused target if (CurrentDetectable != null) { ProcessCurrentDetectable(); return; } // check all detected targets var itemsToRemove = new List <DetectedTarget>(); foreach (KeyValuePair <IDetectable, DetectedTarget> keyPair in _detectedTargets) { DetectedTarget entry = keyPair.Value; entry.DetectionValue += entry.DetectedThisFrame ? Time.deltaTime : -Time.deltaTime; // if this target has reached the detection threshold if (entry.DetectionValue >= DetectionThreshold) { DetectionThresholdHit(entry); break; } // if there is no highest or this detection value is higher if (HighestDetectedTarget == null || entry.DetectionValue > HighestDetectedTarget.DetectionValue) { HighestDetectedTarget = entry; } // if this has reached 0 detection if (entry.DetectionValue <= 0f && !entry.DetectedThisFrame) { itemsToRemove.Add(entry); } // reset the entry entry.DetectedThisFrame = false; } // remove all expired detection targets foreach (var item in itemsToRemove) { _detectedTargets.Remove(item.Target); } }