コード例 #1
0
        protected void ParseColliders(
            int numFound,
            DetectionConstraint constraint,
            Matrix4x4 worldToLocalMatrix)
        {
            Vector3 sensorPos = m_Transform.position;

            for (int i = 0; i < numFound; i++)
            {
                if (m_Settings.IsDetectableTag(
                        m_ColliderBuffer[i].tag,
                        out PointDetectionType type))
                {
                    var detectable = DetectableGameObject.GetCached(m_ColliderBuffer[i]);
                    // Need to filter out compound collider duplicate results,
                    // as each collider is a key in DetectableGameObject's cache.
                    // We also ignore the sensor owner if there is a
                    // DetectableGameObject parent to the sensor.
                    if (detectable != m_Owner && !Result.Contains(detectable))
                    {
                        m_NormPoints.Clear();
                        m_WorldPoints.Clear();

                        switch (type)
                        {
                        case PointDetectionType.Position:
                            m_WorldPoints.Add(detectable.GetWorldPosition());
                            break;

                        case PointDetectionType.ClosestPoint:
                            m_WorldPoints.Add(detectable.GetClosestWorldPoint(sensorPos));
                            break;

                        case PointDetectionType.Shape:
                            float normDistance = constraint.GetNormalizedDistance(
                                worldToLocalMatrix.MultiplyPoint3x4(
                                    detectable.GetClosestWorldPoint(sensorPos)));
                            m_WorldPoints.AddRange(
                                detectable.GetShapeWorldPoints(normDistance));
                            break;
                        }

                        for (int j = 0, c = m_WorldPoints.Count; j < c; j++)
                        {
                            if (constraint.ContainsPoint(
                                    worldToLocalMatrix.MultiplyPoint3x4(m_WorldPoints[j]),
                                    out Vector3 normPoint))
                            {
                                m_NormPoints.Add(normPoint);
                            }
                        }

                        if (m_NormPoints.Count > 0)
                        {
                            Result.Add(detectable, m_NormPoints);
                        }
                    }
                }
            }
        }
コード例 #2
0
        protected void ParseColliders(int n, Constraint constraint, Matrix4x4 worldToLocalMatrix)
        {
            Vector3 sensorPos = m_Transform.position;

            for (int i = 0; i < n; i++)
            {
                if (m_Settings.IsDetectableTag(m_Buffer[i].tag, out ColliderDetectionType type))
                {
                    var detectable = DetectableGameObject.GetCached(m_Buffer[i]);
                    // Need to filter out compound collider duplicate results,
                    // as each collider is a key in DetectableGameObject's cache.
                    // NOTE
                    // We also skip the sensor owner if there's a DetectableGameObject
                    // parent to the sensor.
                    // Although the owner could be excluded by setting the minimum detection
                    // distance large enough for 3D, it's better to avoid checking the
                    // owner's points at every step in the first place.
                    if (detectable != m_Owner && !Result.Contains(detectable))
                    {
                        m_TmpNormPoints.Clear();
                        m_TmpWorldPoints.Clear();

                        switch (type)
                        {
                        case ColliderDetectionType.Position:
                            m_TmpWorldPoints.Add(detectable.GetPosition());
                            break;

                        case ColliderDetectionType.ClosestPoint:
                            m_TmpWorldPoints.Add(detectable.GetClosestPoint(sensorPos));
                            break;

                        case ColliderDetectionType.Shape:
                            m_TmpWorldPoints.AddRange(detectable.GetShapePoints(
                                                          constraint.NormalizeDistance(
                                                              worldToLocalMatrix.MultiplyPoint3x4(
                                                                  detectable.GetPosition()))));
                            break;
                        }

                        for (int j = 0, c = m_TmpWorldPoints.Count; j < c; j++)
                        {
                            if (constraint.ContainsPoint(
                                    worldToLocalMatrix.MultiplyPoint3x4(m_TmpWorldPoints[j]),
                                    out Vector3 normalized))
                            {
                                m_TmpNormPoints.Add(normalized);
                            }
                        }

                        if (m_TmpNormPoints.Count > 0)
                        {
                            Result.Add(detectable, m_TmpNormPoints);
                        }
                    }
                }
            }
        }