Пример #1
0
        private void Remove(ModSessionComponent component)
        {
            var myType = component.GetType();
            List <RuntimeSessionComponent> list;

            if (m_componentDictionary.TryGetValue(myType, out list))
            {
                for (var i = 0; i < list.Count; i++)
                {
                    if (list[i].Component != component)
                    {
                        continue;
                    }
                    if (list[i].Dependents.Count > 0)
                    {
                        FallbackLogger.Log(MyLogSeverity.Critical, "Unable to remove {0} because it still has {1} dependents", component.GetType(), list[i].Dependents.Count);
                        using (FallbackLogger.IndentUsing())
                            foreach (var dep in list[i].Dependents)
                            {
                                FallbackLogger.Log(MyLogSeverity.Critical, "Dependent: {0}", dep.Component.GetType());
                            }
                        throw new ArgumentException("Can't remove " + component.GetType() + " because it still has dependents");
                    }
                    foreach (var dep in list[i].Dependencies)
                    {
                        dep.Dependents.Remove(list[i]);
                    }
                    list.RemoveAtFast(i);
                    break;
                }
                if (list.Count == 0)
                {
                    m_componentDictionary.Remove(myType);
                }
            }
            foreach (var dep in component.SuppliedComponents)
            {
                m_dependencySatisfyingComponents.Remove(dep);
            }
            for (var i = 0; i < m_orderedComponentList.Count; i++)
            {
                if (m_orderedComponentList[i].Component == component)
                {
                    m_orderedComponentList.RemoveAt(i);
                    break;
                }
            }
            component.Detached();
            ComponentDetached?.Invoke(component);
        }
Пример #2
0
 public void Detach()
 {
     ApplyComponentChanges();
     if (m_attached)
     {
         for (var i = m_orderedComponentList.Count - 1; i >= 0; i--)
         {
             m_orderedComponentList[i].Component.Detached();
             ComponentDetached?.Invoke(m_orderedComponentList[i].Component);
         }
     }
     m_attached = false;
     m_orderedComponentList.Clear();
 }
 internal void DetachComponent(EntityComponent component)
 {
     _components.Remove(component);
     (component as IDisposable)?.Dispose();
     ComponentDetached?.Invoke(this, component);
 }