Exemple #1
0
        public void Update(GridType type)
        {
            LayerMask = 0;
            m_Tags.Clear();
            m_ObservationIndices.Clear();
            m_ModifierTypes.Clear();
            m_DetectionTypes.Clear();

            for (int i = m_SettingsByTag.Count - 1; i >= 0; i--)
            {
                GameObjectSettings settings = m_SettingsByTag[i];

                if (settings.Detectable == null)
                {
                    m_SettingsByTag.RemoveAt(i);
                }
                else if (settings.Enabled)
                {
                    settings.Update();
                    string tag = settings.Tag;

                    if (m_Tags.Contains(tag))
                    {
                        // Can occur if tag is changed on object that was already added.
                        Debug.LogError($"Duplicate tag '{tag}' found, tags must be distinct.");
                    }
                    else
                    {
                        m_Tags.Add(tag);
                        m_DetectionTypes.Add(tag, settings.DetectionType);
                        m_ModifierTypes.Add(tag, settings.DetectionType == ColliderDetectionType.Shape
                            ? settings.ShapeModifier : ShapeModifierType.None);

                        if (settings.ObservationsCount > 0)
                        {
                            m_ObservationIndices.Add(tag, settings.GetObservationIndices());
                        }
                        else if (type == GridType._2D)
                        {
                            Debug.LogError("No observations found in detectable object '" + tag
                                           + "'. 2D detection requires at least one observation.");
                        }
                    }

                    LayerMask |= 1 << settings.Detectable.gameObject.layer;
                }
            }
            m_Tags.Reverse();
        }
        /// <summary>
        /// Validates list of <see cref="GameObjectSettings"/>, stores them by tag.
        /// </summary>
        /// <param name="settingsList">List of <see cref="GameObjectSettings"/></param>
        /// <returns>The number of required observation channels</returns>
        public int Validate(List <GameObjectSettings> settingsList)
        {
            LayerMask = 0;
            int numReqChannels = 0;

            m_Tags.Clear();
            m_Observables.Clear();
            m_DetectionTypes.Clear();
            m_PointModifierTypes.Clear();

            for (int i = settingsList.Count - 1; i >= 0; i--)
            {
                GameObjectSettings settings = settingsList[i];

                if (settings.Detectable == null)
                {
                    // Remove null references from list.
                    settingsList.RemoveAt(i);
                }
                else
                {
                    settings.Validate();

                    if (settings.Enabled)
                    {
                        string tag = settings.Tag;

                        if (m_Tags.Contains(tag))
                        {
                            settingsList.RemoveAt(i);
                            // Can occur if tag is changed on object that was already added,
                            // or if entry was duplicated by pressing list +.
                            Debug.LogWarning($"Duplicate tag '{tag}' found, tags must be distinct. " +
                                             "Removing detectable object from list.");
                        }
                        else
                        {
                            m_Tags.Add(tag);
                            m_DetectionTypes.Add(tag, settings.DetectionType);
                            m_PointModifierTypes.Add(tag,
                                                     settings.DetectionType == PointDetectionType.Shape
                                ? settings.Modifier : PointModifierType.None);

                            var obs    = settings.GetEnabledObservables();
                            int numObs = obs.Count();
                            if (numObs == 0)
                            {
                                Debug.LogError($"No enabled observables found for tag '{tag}'. " +
                                               "A detectable gameobject requires at least one observable.");
                            }
                            else
                            {
                                m_Observables.Add(tag, obs);
                                numReqChannels += numObs;
                            }
                        }

                        LayerMask |= 1 << settings.Detectable.gameObject.layer;
                    }
                }
            }

            // Was iterating down before.
            m_Tags.Reverse();

            return(numReqChannels);
        }