Beispiel #1
0
        public void Pick(Vector3[] samplePoints, int samplePointCount, List <Tuple <GameObject, RaycastHit> > results)
        {
            // early exit if 2 sample points or less
            if (samplePointCount <= 2)
            {
                Debug.LogError($"[{nameof(SpatialSelector)}] cannot use Raycast(Vector3[] samplePoints, [...]) " +
                               "with 2 or less sample points! Try using Raycast(Ray ray, [...]) instead!");
                return;
            }

            // init chain of rays from one sample point to the next
            if (m_RayDatas == null || m_RayDatas.Length != samplePointCount - 1)
            {
                m_RayDatas = new RayData[samplePointCount - 1];
            }

            for (var i = 0; i < m_RayDatas.Length; ++i)
            {
                m_RayDatas[i].ray.origin = samplePoints[i];
                var diff = samplePoints[i + 1] - samplePoints[i];
                m_RayDatas[i].ray.direction = diff;
                m_RayDatas[i].length        = diff.magnitude;
            }

            // narrow down the possible objects using the spatial picker
            SpatialPicker.Pick(samplePoints, samplePointCount, m_SpatialObjects);

            PreRaycast();
            RaycastSamplePointsInternal(results);
            PostRaycast(results);
        }
Beispiel #2
0
        void PrePicking(Ray ray, List <Tuple <GameObject, RaycastHit> > results)
        {
            var transformedRay = new Ray(WorldRoot.InverseTransformPoint(ray.origin), WorldRoot.InverseTransformDirection(ray.direction));

            // narrow down the possible objects using the spatial picker
            SpatialPicker.Pick(transformedRay, m_SpatialObjects);

            PreRaycast();
            RaycastInternal(ray, results);
        }
Beispiel #3
0
        public void Pick(Ray ray, List <Tuple <GameObject, RaycastHit> > results, string[] flagsExcluded = null)
        {
            var transformedRay = new Ray(WorldRoot.InverseTransformPoint(ray.origin), WorldRoot.InverseTransformDirection(ray.direction));

            // narrow down the possible objects using the spatial picker
            SpatialPicker.Pick(transformedRay, m_SpatialObjects, flagsExcluded);

            PreRaycast(m_SpatialObjects);
            RaycastInternal(ray, results);
            PostRaycast(results);
        }
Beispiel #4
0
        public void Pick(Vector3[] samplePoints, int samplePointCount, List <Tuple <GameObject, RaycastHit> > results, string[] flagsExcluded = null)
        {
            PrePickSamplePoints(samplePoints, samplePointCount);

            // narrow down the possible objects using the spatial picker
            SpatialPicker.Pick(samplePoints, samplePointCount, m_SpatialObjects, flagsExcluded);

            PreRaycast(m_SpatialObjects);
            RaycastSamplePointsInternal(results);
            PostRaycast(results);
        }
Beispiel #5
0
        public void Pick(float distance, List <Tuple <GameObject, RaycastHit> > results, Transform origin)
        {
            results.Clear();
            SpatialPicker.Pick(distance, m_SpatialObjects, origin);
            foreach (var spatialObject in m_SpatialObjects)
            {
                if (spatialObject.loadedObject == null)
                {
                    continue;
                }

                results.Add(new Tuple <GameObject, RaycastHit>(spatialObject.loadedObject, new RaycastHit()));
            }
        }
Beispiel #6
0
        public void Pick(float distance, List <Tuple <GameObject, RaycastHit> > results, Transform origin, string[] flagsExcluded = null)
        {
            results.Clear();
            SpatialPicker.Pick(distance, m_SpatialObjects, origin, flagsExcluded);
            foreach (var spatialObject in m_SpatialObjects)
            {
                if (spatialObject.LoadedObject == null)
                {
                    continue;
                }

                results.Add(new Tuple <GameObject, RaycastHit>(spatialObject.LoadedObject, k_BlankRaycastHit));
            }
        }