Exemple #1
0
        void SortTargets()
        {
            interation += Time.deltaTime;
            if (interation > updateTargetInteration)
            {
                interation -= updateTargetInteration;
                if (targetsInArea == null || targetsInArea.Count < 2)
                {
                    if (targetsInArea != null && targetsInArea.Count > 0)
                    {
                        currentLookTarget = targetsInArea[0];
                    }
                    return;
                }

                for (int i = targetsInArea.Count - 1; i >= 0; i--)
                {
                    if (targetsInArea[i] == null)
                    {
                        targetsInArea.RemoveAt(i);
                    }
                }
                targetsInArea.Sort(delegate(vLookTarget c1, vLookTarget c2)
                {
                    return(Vector3.Distance(this.transform.position, c1 != null ? c1.transform.position : Vector3.one *Mathf.Infinity).CompareTo
                               ((Vector3.Distance(this.transform.position, c2 != null ? c2.transform.position : Vector3.one * Mathf.Infinity))));
                });
                if (targetsInArea.Count > 0)
                {
                    currentLookTarget = targetsInArea[0];
                }
            }
        }
Exemple #2
0
        static LookPoints GetLookPoints(vLookTarget lookTarget)
        {
            LookPoints points        = new LookPoints();
            var        centerArea    = lookTarget.centerArea;
            var        sizeArea      = lookTarget.sizeArea;
            var        lookTransform = lookTarget.transform;

            points.frontTopLeft     = new Vector3(centerArea.x - sizeArea.x, centerArea.y + sizeArea.y, centerArea.z - sizeArea.z);
            points.frontTopRight    = new Vector3(centerArea.x + sizeArea.x, centerArea.y + sizeArea.y, centerArea.z - sizeArea.z);
            points.frontBottomLeft  = new Vector3(centerArea.x - sizeArea.x, centerArea.y - sizeArea.y, centerArea.z - sizeArea.z);
            points.frontBottomRight = new Vector3(centerArea.x + sizeArea.x, centerArea.y - sizeArea.y, centerArea.z - sizeArea.z);
            points.backTopLeft      = new Vector3(centerArea.x - sizeArea.x, centerArea.y + sizeArea.y, centerArea.z + sizeArea.z);
            points.backTopRight     = new Vector3(centerArea.x + sizeArea.x, centerArea.y + sizeArea.y, centerArea.z + sizeArea.z);
            points.backBottomLeft   = new Vector3(centerArea.x - sizeArea.x, centerArea.y - sizeArea.y, centerArea.z + sizeArea.z);
            points.backBottomRight  = new Vector3(centerArea.x + sizeArea.x, centerArea.y - sizeArea.y, centerArea.z + sizeArea.z);

            points.frontTopLeft     = lookTransform.TransformPoint(points.frontTopLeft);
            points.frontTopRight    = lookTransform.TransformPoint(points.frontTopRight);
            points.frontBottomLeft  = lookTransform.TransformPoint(points.frontBottomLeft);
            points.frontBottomRight = lookTransform.TransformPoint(points.frontBottomRight);
            points.backTopLeft      = lookTransform.TransformPoint(points.backTopLeft);
            points.backTopRight     = lookTransform.TransformPoint(points.backTopRight);
            points.backBottomLeft   = lookTransform.TransformPoint(points.backBottomLeft);
            points.backBottomRight  = lookTransform.TransformPoint(points.backBottomRight);
            return(points);
        }
Exemple #3
0
 public void RemoveLookTarget(vLookTarget target)
 {
     if (targetsInArea.Contains(target))
     {
         targetsInArea.Remove(target);
     }
     if (currentLookTarget == target)
     {
         currentLookTarget = null;
     }
 }
Exemple #4
0
 /// <summary>
 /// Set vLookTarget
 /// </summary>
 /// <param name="target"></param>
 public void SetLookTarget(vLookTarget target, bool priority = false)
 {
     if (!targetsInArea.Contains(target))
     {
         targetsInArea.Add(target);
     }
     if (priority)
     {
         currentLookTarget = target;
     }
 }
Exemple #5
0
 public void OnDetect(Collider other)
 {
     if (tagsToDetect.Contains(other.gameObject.tag) && other.GetComponent <vLookTarget>() != null)
     {
         currentLookTarget = other.GetComponent <vLookTarget>();
         var headTrack = other.GetComponentInParent <vHeadTrack>();
         if (!targetsInArea.Contains(currentLookTarget) && (headTrack == null || headTrack != this))
         {
             targetsInArea.Add(currentLookTarget);
             SortTargets();
             currentLookTarget = targetsInArea[0];
         }
     }
 }
Exemple #6
0
 public void OnLost(Collider other)
 {
     if (tagsToDetect.Contains(other.gameObject.tag) && other.GetComponentInParent <vLookTarget>() != null)
     {
         currentLookTarget = other.GetComponentInParent <vLookTarget>();
         if (targetsInArea.Contains(currentLookTarget))
         {
             targetsInArea.Remove(currentLookTarget);
         }
         SortTargets();
         if (targetsInArea.Count > 0)
         {
             currentLookTarget = targetsInArea[0];
         }
         else
         {
             currentLookTarget = null;
         }
     }
 }
Exemple #7
0
        /// <summary>
        /// Check if anny corner points of LookTarget area is visible from observer
        /// </summary>
        /// <param name="lookTarget">principal transform of lookTarget</param>
        /// <param name="from">observer point</param>
        /// <param name="debug">Draw lines </param>
        /// <returns></returns>
        public static bool IsVisible(this vLookTarget lookTarget, Vector3 from, bool debug = false)
        {
            if (lookTarget.HideObject)
            {
                return(false);
            }
            LookPoints points = GetLookPoints(lookTarget);

            if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.None)
            {
                return(true);
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.SingleCast)
            {
                if (CastPoint(from, lookTarget.transform.TransformPoint(lookTarget.centerArea), lookTarget.transform, debug))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.BoxCast)
            {
                if (CastPoint(from, points.frontTopLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontTopRight, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomRight, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopRight, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomLeft, lookTarget.transform, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomRight, lookTarget.transform, debug))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #8
0
        /// <summary>
        /// Check if anny corner points of LookTarget area is visible from observer
        /// </summary>
        /// <param name="lookTarget">principal transform of lookTarget</param>
        /// <param name="from">observer point</param>
        /// <param name="layerMask">Layer to check</param>
        /// <param name="debug">Draw lines </param>
        /// <returns></returns>
        public static bool IsVisible(this vLookTarget lookTarget, Vector3 from, LayerMask layerMask, bool debug = false)
        {
            if (lookTarget.HideObject)
            {
                return(false);
            }

            if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.None)
            {
                if (lookTarget.useLimitToDetect && Vector3.Distance(from, lookTarget.transform.position) > lookTarget.minDistanceToDetect)
                {
                    return(false);
                }

                return(true);
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.SingleCast)
            {
                if (lookTarget.useLimitToDetect && Vector3.Distance(from, lookTarget.centerArea) > lookTarget.minDistanceToDetect)
                {
                    return(false);
                }
                if (CastPoint(from, lookTarget.transform.TransformPoint(lookTarget.centerArea), lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (lookTarget.visibleCheckType == vLookTarget.VisibleCheckType.BoxCast)
            {
                if (lookTarget.useLimitToDetect && Vector3.Distance(from, lookTarget.transform.position) > lookTarget.minDistanceToDetect)
                {
                    return(false);
                }
                LookPoints points = GetLookPoints(lookTarget);

                if (CastPoint(from, points.frontTopLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontTopRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.frontBottomRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backTopRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomLeft, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }

                if (CastPoint(from, points.backBottomRight, lookTarget.transform, layerMask, debug))
                {
                    return(true);
                }
            }
            return(false);
        }