Пример #1
0
        public void Dispose()
        {
            if (!IsCreated)
            {
                throw new ArgumentException("The World has already been Disposed.");
            }
            // Debug.LogError("Dispose World "+ Name + " - " + GetHashCode());

            if (allWorlds.Contains(this))
            {
                allWorlds.Remove(this);
            }

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            m_AllowGetManager = false;
#endif
            // Destruction should happen in reverse order to construction
            ScriptBehaviourManager em = null;
            for (int i = m_BehaviourManagers.Count - 1; i >= 0; --i)
            {
                var mgr = m_BehaviourManagers[i];
                if (mgr is EntityManager)
                {
                    em = mgr;
                    continue;
                }
                try
                {
                    mgr.DestroyInstance();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            // Destroy EntityManager last
            if (em != null)
            {
                try
                {
                    em.DestroyInstance();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            if (Active == this)
            {
                Active = null;
            }

            m_BehaviourManagers.Clear();
            m_BehaviourManagerLookup.Clear();

            m_BehaviourManagers      = null;
            m_BehaviourManagerLookup = null;
        }
Пример #2
0
        private void RemoveManagerInteral(ScriptBehaviourManager manager)
        {
            if (!m_BehaviourManagers.Remove(manager))
            {
                throw new ArgumentException($"manager does not exist in the world");
            }
            ++Version;

            var type = manager.GetType();

            while (type != typeof(ScriptBehaviourManager))
            {
                if (m_BehaviourManagerLookup[type] == manager)
                {
                    m_BehaviourManagerLookup.Remove(type);

                    foreach (var otherManager in m_BehaviourManagers)
                    {
                        if (otherManager.GetType().IsSubclassOf(type))
                        {
                            AddTypeLookup(otherManager.GetType(), otherManager);
                        }
                    }
                }

                type = type.BaseType;
            }
        }
Пример #3
0
        public void DestroyManager(ScriptBehaviourManager manager)
        {
            CheckGetOrCreateManager();

            RemoveManagerInternal(manager);
            manager.DestroyInstance();
        }
        internal static T[] GetAllInjectedManagers <T>(ScriptBehaviourManager host, World world) where T : ScriptBehaviourManager
        {
            var result = new List <T>();
            var fields = host.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

            foreach (var field in fields)
            {
                var attr = field.GetCustomAttributes(typeof(InjectAttribute), true);
                if (attr.Length == 0)
                {
                    continue;
                }

                if (!field.FieldType.IsClass)
                {
                    continue;
                }

                if (!field.FieldType.IsSubclassOf(typeof(T)))
                {
                    continue;
                }

                result.Add((T)world.GetOrCreateManager(field.FieldType));
            }

            return(result.ToArray());
        }
 private static void InjectConstructorDependencies(ScriptBehaviourManager manager, World world, FieldInfo field)
 {
     if (field.FieldType.IsSubclassOf(typeof(ScriptBehaviourManager)))
     {
         field.SetValue(manager, world.GetOrCreateManager(field.FieldType));
     }
     else
     {
         ThrowUnsupportedInjectException(field);
     }
 }
Пример #6
0
 public DependantBehavior(ScriptBehaviourManager man)
 {
     this.Manager      = man;
     this.MinInsertPos = 0;
     this.MaxInsertPos = 0;
     this.spawnsJobs   = false;
     this.WaitsForJobs = false;
     this.UnvalidatedSystemsUpdatingBefore  = 0;
     this.LongestSystemsUpdatingBeforeChain = 0;
     this.LongestSystemsUpdatingAfterChain  = 0;
 }
Пример #7
0
        private void AddTypeLookup(Type type, ScriptBehaviourManager manager)
        {
            while (type != typeof(ScriptBehaviourManager))
            {
                if (!m_BehaviourManagerLookup.ContainsKey(type))
                {
                    m_BehaviourManagerLookup.Add(type, manager);
                }

                type = type.BaseType;
            }
        }
        internal static T[] GetAllInjectedManagers <T>(ScriptBehaviourManager host, World world) where T : ScriptBehaviourManager
        {
            List <T> list = new List <T>();

            foreach (FieldInfo info in host.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                object[] customAttributes = info.GetCustomAttributes(typeof(InjectAttribute), true);
                bool     flag             = customAttributes.Length == 0;
                if ((!flag && info.FieldType.IsClass) && info.FieldType.IsSubclassOf(typeof(T)))
                {
                    list.Add((T)world.GetOrCreateManager(info.FieldType));
                }
            }
            return(list.ToArray());
        }
Пример #9
0
 public void DestroyManager(ScriptBehaviourManager manager)
 {
     RemoveManagerInteral(manager);
     manager.DestroyInstance();
 }
Пример #10
0
 public DummyDelagateWrapper(ScriptBehaviourManager man)
 {
     m_Manager = man;
 }