コード例 #1
0
        public bool Contains(MyTriggerComponent trigger)
        {
            m_updateLock = true;

            foreach (var tuple in m_removeCacheTrigger)
            {
                if (tuple.Item2 == trigger)
                {
                    return(false);
                }
            }

            if (m_addCache.Contains(trigger))
            {
                return(true);
            }

            foreach (var triggerList in m_triggers.Values)
            {
                if (triggerList.Contains(trigger))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public void AddTrigger(MyTriggerComponent trigger)
        {
            Debug.Assert(trigger != null, "Horrible Assertion! Call a programmer! Hurry!");
            MySandboxGame.AssertUpdateThread();

            if (Contains(trigger))
            {
                return;
            }

            using (m_dictionaryLock.AcquireExclusiveUsing())
            {
                CachingHashSet triggerSet;
                if (m_triggers.TryGetValue((MyEntity)trigger.Entity, out triggerSet))
                {
                    triggerSet.Add(trigger);
                }
                else
                {
                    m_triggers[(MyEntity)trigger.Entity] = new CachingHashSet {
                        trigger
                    };
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Selects the closest trigger to provided position.
        /// </summary>
        /// <param name="position">Considered position.</param>
        public void SelectClosest(Vector3D position)
        {
            var minLength = double.MaxValue;

            // Change the debug draw color from previously selected to default color.
            if (SelectedTrigger != null)
            {
                SelectedTrigger.CustomDebugColor = Color.Red;
            }

            // Find the min length
            foreach (var trigger in m_currentQuery)
            {
                var length = (trigger.Center - position).LengthSquared();
                if (length < minLength)
                {
                    minLength       = length;
                    SelectedTrigger = trigger;
                }
            }

            if (Math.Abs(minLength - double.MaxValue) < double.Epsilon)
            {
                SelectedTrigger = null;
            }

            // Change the trigger debug draw color to selected.
            if (SelectedTrigger != null)
            {
                SelectedTrigger.CustomDebugColor = Color.Yellow;
            }
        }
コード例 #4
0
 public void RemoveTrigger(MyEntity entity, MyTriggerComponent trigger)
 {
     if (m_updateLock)
     {
         m_removeCacheTrigger.Add(new MyTuple <MyEntity, MyTriggerComponent>(entity, trigger));
     }
     else
     {
         RemoveTriggerCached(entity, trigger);
     }
 }
コード例 #5
0
 public void AddTrigger(MyTriggerComponent trigger)
 {
     if (m_updateLock)
     {
         m_addCache.Add(trigger);
     }
     else
     {
         AddTriggerCached(trigger);
     }
 }
コード例 #6
0
 public void RemoveTrigger(MyEntity entity, MyTriggerComponent trigger)
 {
     using (m_dictionaryLock.AcquireExclusiveUsing())
     {
         CachingHashSet triggerSet;
         if (m_triggers.TryGetValue(entity, out triggerSet))
         {
             triggerSet.Remove(trigger);
         }
     }
 }
コード例 #7
0
 private void AddTriggerCached(MyTriggerComponent trigger)
 {
     if (!m_triggers.ContainsKey((MyEntity)trigger.Entity))
     {
         m_triggers.Add((MyEntity)trigger.Entity, new List <MyTriggerComponent> {
             trigger
         });
     }
     else
     {
         Debug.Assert(!m_triggers[(MyEntity)trigger.Entity].Contains(trigger));
         m_triggers[(MyEntity)trigger.Entity].Add(trigger);
     }
 }
コード例 #8
0
 public bool Contains(MyTriggerComponent trigger)
 {
     using (m_dictionaryLock.AcquireSharedUsing())
     {
         foreach (var triggerSet in m_triggers.Values)
         {
             if (triggerSet.Contains(trigger))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #9
0
 private void RemoveTriggerCached(MyEntity entity, MyTriggerComponent trigger)
 {
     if (m_triggers.ContainsKey(entity) && m_triggers[entity].Contains(trigger))
     {
         if (m_triggers[entity].Count == 1)
         {
             m_triggers[entity].Clear();
             m_triggers.Remove(entity);
         }
         else
         {
             m_triggers[entity].Remove(trigger);
         }
     }
 }
コード例 #10
0
        public MyEntity GetTriggersEntity(string triggerName, out MyTriggerComponent foundTrigger)
        {
            foundTrigger = null;

            foreach (var pair in m_triggers)
            {
                foreach (var component in pair.Value)
                {
                    var areaTrigger = component as MyAreaTriggerComponent;
                    if (areaTrigger != null && areaTrigger.Name == triggerName)
                    {
                        foundTrigger = component;
                        return(pair.Key);
                    }
                }
            }

            return(null);
        }
コード例 #11
0
        public MyEntity GetTriggerEntity(string entityName, out MyTriggerComponent foundTrigger)
        {
            foundTrigger = null;
            bool orig = m_updateLock;

            m_updateLock = true;
            foreach (var triggerList in m_triggers.Values)
            {
                foreach (var trigger in triggerList)
                {
                    if (trigger is MyAreaTriggerComponent && ((MyAreaTriggerComponent)trigger).Name.Equals(entityName))
                    {
                        foundTrigger = trigger;
                        return((MyEntity)trigger.Entity);
                    }
                }
            }
            m_updateLock = orig;
            return(null);
        }