Пример #1
0
        private void TargetUnDetected(SightTargetInfo sightInfo)
        {
            sightInfo.isInFOV = false; // Incase not updating anymore, set manually
//            GetCurrentPositionSample(sightInfo, out sightInfo.lastSeenAt);

            if (config.extrapolatePath)
            {
                extrapolator.ExtrapolatePath(sightInfo.target, 1f, out sightInfo.extrapolatedSampleData);
            }

            observer.gameObject.GetComponents(_observerCallbacksList);
            foreach (var callback in _observerCallbacksList)
            {
                callback.OnUnDetectedTarget(sightInfo);
            }

            sightInfo.target.gameObject.GetComponents(_sightTargetCallbacksList);
            foreach (var callback in _sightTargetCallbacksList)
            {
                callback.OnUnDetectedByObserver(sightInfo);
            }

            extrapolator.ClearSamplesForTarget(sightInfo.target);
            sightInfo.ResetDetection();
        }
Пример #2
0
        public void Update(SightTargetInfo sightInfo)
        {
            Assert.IsTrue(sightInfo.target.IsDestroyed() == false, "Null object as target given, this is not allowed!"); // Note: This doesn't work because of the interface implementation, managed heap object remains, unmanaged code is destroyed.
            Assert.IsTrue(sightInfo.sight == this, "SightTargetInfo given that doesn't belong to this sight.");
            if (sightInfo.target.enabled == false)
            {
                return;
            }

            sightInfo.isInFOV = IsTargetInFOV(sightInfo.target);

            float hitFactor = 0f;

            if (sightInfo.isInFOV)
            {
                switch (sightInfo.target.indexingConfig.indexingType)
                {
                case TargetIndexingType.Manual:
                    hitFactor = DoManualRaycasting(sightInfo);

                    break;

                case TargetIndexingType.Automatic:
                    hitFactor = DoAutomaticRaycasting(sightInfo);

                    break;

                default:
                    throw new ArgumentOutOfRangeException(typeof(TargetIndexingType).Name + " type not found (index: " + sightInfo.target.indexingConfig.indexingType + ")");
                }
            }


            sightInfo.distance      = Vector3.Distance(transform.position, sightInfo.target.transform.position);
            sightInfo.visibleFactor = Mathf.Clamp01(hitFactor * sightInfo.target.config.visibilityMultiplier);

            if (sightInfo.isDetected == false)
            {
                if (hitFactor > 0f)
                {
                    TryToDetectTarget(sightInfo);
                }
            }

            // Enough hits to detect / see target
            if (hitFactor >= GetMinVisibilityFactor(sightInfo.target))
            {
                sightInfo.visibleForSeconds += config.updateInterval;
                GetCurrentPositionSample(sightInfo, out sightInfo.lastSeenAt);

                if (config.extrapolatePath)
                {
                    extrapolator.TakeSample(sightInfo.target);
                }

                if (sightInfo.isDetected == false)
                {
                    DetectingTarget(sightInfo);
                    if (sightInfo.visibleForSeconds >= sightInfo.target.config.detectionTime)
                    {
                        TargetDetected(sightInfo);
                    }
                }
            }
            else
            {
                // Not visible from current samples taken. Still marked visible
                if (sightInfo.isDetected)
                {
                    TargetUnDetected(sightInfo);
                }

                if (sightInfo.visibleForSeconds > 0f)
                {
                    StopDetectingTarget(sightInfo);
                }

                sightInfo.ResetDetection();
            }
        }