Exemple #1
0
        public static void Initialize()
        {
            var world = new World(k_DefaultWorldName);

            World.Active   = world;
            s_CreatedWorld = world;

            // Register hybrid injection hooks
            InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook());

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
            {
                var allTypes = ass.GetTypes();

                // Create all ComponentSystem
                var systemTypes = allTypes.Where(t => t.IsSubclassOf(typeof(ComponentSystemBase)) && !t.IsAbstract && !t.ContainsGenericParameters && t.GetCustomAttributes(typeof(DisableAutoCreationAttribute), true).Length == 0);
                foreach (var type in systemTypes)
                {
                    GetBehaviourManagerAndLogException(world, type);
                }
            }

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
        }
        static void DomainUnloadShutdown()
        {
            World.DisposeAllWorlds();

            WordStorage.Instance.Dispose();
            WordStorage.Instance = null;
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null);
        }
Exemple #3
0
        static void DomainUnloadShutdown()
        {
            if (World.Active == s_CreatedWorld)
            {
                World.Active.Dispose();
                World.Active = null;

                ScriptBehaviourUpdateOrder.UpdatePlayerLoop();
            }
            else
            {
                Debug.LogError("World has already been destroyed");
            }
        }
Exemple #4
0
        public static void Initialize(string worldName, bool editorWorld)
        {
            var world = new World(worldName);

            World.Active = world;

            // Register hybrid injection hooks
            InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook());

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            IEnumerable <Type> allTypes;

            foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    allTypes = ass.GetTypes();
                }
                catch (ReflectionTypeLoadException e)
                {
                    allTypes = e.Types.Where(t => t != null);
                    Debug.LogWarning("DefaultWorldInitialization failed loading assembly: " + ass.Location);
                }

                // Create all ComponentSystem
                CreateBehaviourManagersForMatchingTypes(editorWorld, allTypes, world);
            }

            foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    allTypes = ass.GetTypes();
                }
                catch (ReflectionTypeLoadException e)
                {
                    allTypes = e.Types.Where(t => t != null);
                    Debug.LogWarning("DefaultWorldInitialization failed loading assembly: " + ass.Location);
                }

                AddComponentSystemPatchesForMatchingTypes(editorWorld, allTypes, world);
            }

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
        }
Exemple #5
0
        internal static void DomainUnloadOrPlayModeChangeShutdown()
        {
            if (!s_UnloadOrPlayModeChangeShutdownRegistered)
            {
                return;
            }

            World.DisposeAllWorlds();

            WordStorage.Instance.Dispose();
            WordStorage.Instance = null;
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null);

            s_UnloadOrPlayModeChangeShutdownRegistered = false;

            DefaultWorldDestroyed?.Invoke();
        }
        internal static void DomainUnloadOrPlayModeChangeShutdown()
        {
#if !UNITY_DOTSRUNTIME
            if (!s_UnloadOrPlayModeChangeShutdownRegistered)
            {
                return;
            }

            var playerLoop = PlayerLoop.GetCurrentPlayerLoop();
            foreach (var w in World.s_AllWorlds)
            {
                ScriptBehaviourUpdateOrder.RemoveWorldFromPlayerLoop(w, ref playerLoop);
            }
            PlayerLoop.SetPlayerLoop(playerLoop);

            World.DisposeAllWorlds();

            s_UnloadOrPlayModeChangeShutdownRegistered = false;

            DefaultWorldDestroyed?.Invoke();
#endif
        }
Exemple #7
0
        /// <summary>
        /// Initializes the default world or runs ICustomBootstrap if one is available.
        /// </summary>
        /// <param name="defaultWorldName">The name of the world that will be created. Unless there is a custom bootstrap.</param>
        /// <param name="editorWorld">Editor worlds by default only include systems with [ExecuteAlways]. If editorWorld is true, ICustomBootstrap will not be used.</param>
        public static void Initialize(string defaultWorldName, bool editorWorld)
        {
            RegisterUnloadOrPlayModeChangeShutdown();

            if (!editorWorld)
            {
                var bootStrap = CreateBootStrap();
                if (bootStrap != null && bootStrap.Initialize(defaultWorldName))
                {
                    return;
                }
            }

            var world = new World(defaultWorldName, editorWorld ? WorldFlags.Editor : WorldFlags.Game);

            World.DefaultGameObjectInjectionWorld = world;

            var systems = GetAllSystems(WorldSystemFilterFlags.Default, editorWorld);

            AddSystemsToRootLevelSystemGroups(world, systems);
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);

            DefaultWorldInitialized?.Invoke(world);
        }
        public static void Initialize(string worldName, bool editorWorld)
        {
            // Register hybrid injection hooks
            #pragma warning disable 0618
            InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook());
            #pragma warning restore 0618

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            var world = new World(worldName);
            World.Active = world;
            var systems = GetAllSystems(WorldSystemFilterFlags.Default);
            if (systems == null)
            {
                world.Dispose();
                if (World.Active == world)
                {
                    World.Active = null;
                }
                return;
            }

            // create presentation system and simulation system
            InitializationSystemGroup initializationSystemGroup = world.GetOrCreateManager <InitializationSystemGroup>();
            SimulationSystemGroup     simulationSystemGroup     = world.GetOrCreateManager <SimulationSystemGroup>();
            PresentationSystemGroup   presentationSystemGroup   = world.GetOrCreateManager <PresentationSystemGroup>();
            // Add systems to their groups, based on the [UpdateInGroup] attribute.
            foreach (var type in systems)
            {
                // Skip the built-in root-level systems
                if (type == typeof(InitializationSystemGroup) ||
                    type == typeof(SimulationSystemGroup) ||
                    type == typeof(PresentationSystemGroup))
                {
                    continue;
                }
                if (editorWorld)
                {
                    if (Attribute.IsDefined(type, typeof(ExecuteInEditMode)))
                    {
                        Debug.LogError(
                            $"{type} is decorated with {typeof(ExecuteInEditMode)}. Support for this attribute will be deprecated. Please use {typeof(ExecuteAlways)} instead.");
                    }
                    if (!Attribute.IsDefined(type, typeof(ExecuteAlways)))
                    {
                        continue;
                    }
                }

                var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
                if (groups.Length == 0)
                {
                    simulationSystemGroup.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase);
                }

                foreach (var g in groups)
                {
                    var group = g as UpdateInGroupAttribute;
                    if (group == null)
                    {
                        continue;
                    }

                    if (!(typeof(ComponentSystemGroup)).IsAssignableFrom(group.GroupType))
                    {
                        Debug.LogError($"Invalid [UpdateInGroup] attribute for {type}: {group.GroupType} must be derived from ComponentSystemGroup.");
                        continue;
                    }

                    var groupMgr = GetOrCreateManagerAndLogException(world, group.GroupType);
                    if (groupMgr == null)
                    {
                        Debug.LogWarning(
                            $"Skipping creation of {type} due to errors creating the group {group.GroupType}. Fix these errors before continuing.");
                        continue;
                    }
                    var groupSys = groupMgr as ComponentSystemGroup;
                    if (groupSys != null)
                    {
                        groupSys.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase);
                    }
                }
            }

            // Update player loop
            initializationSystemGroup.SortSystemUpdateList();
            simulationSystemGroup.SortSystemUpdateList();
            presentationSystemGroup.SortSystemUpdateList();
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
        }
 static void DomainUnloadShutdown()
 {
     World.DisposeAllWorlds();
     ScriptBehaviourUpdateOrder.UpdatePlayerLoop();
 }