コード例 #1
0
        static void DeclareReferencedObjects(World gameObjectWorld, GameObjectConversionMappingSystem mappingSystem)
        {
            var newAllEntitiesQuery = mappingSystem.Entities
                                      .WithNone <DeclaredReferenceObjectsTag>()
                                      .ToEntityQuery();

            //@TODO: Revert this again once KevinM adds support for inheritance in queries
            //var newGoEntitiesQuery = mappingSystem.Entities
            //    .WithNone<DeclaredReferenceObjectsTag>()
            //    .WithAll<Transform>()
            //    .ToEntityQuery();
            var newGoEntitiesQuery = mappingSystem.GetEntityQuery(
                new EntityQueryDesc
            {
                None = new ComponentType[] { typeof(DeclaredReferenceObjectsTag) },
                All  = new ComponentType[] { typeof(Transform) }
            },
                new EntityQueryDesc
            {
                None = new ComponentType[] { typeof(DeclaredReferenceObjectsTag) },
                All  = new ComponentType[] { typeof(RectTransform) }
            });

            var prefabDeclarers = new List <IDeclareReferencedPrefabs>();
            var declaredPrefabs = new List <GameObject>();

            // loop until no new entities discovered that might need following
            while (!newAllEntitiesQuery.IsEmptyIgnoreFilter)
            {
                using (var newGoEntities = newGoEntitiesQuery.ToEntityArray(Allocator.TempJob))
                {
                    // fetch components that implement IDeclareReferencedPrefabs
                    foreach (var newGoEntity in newGoEntities)
                    {
                        //@TODO: Revert this again once we add support for inheritance in queries
                        //gameObjectWorld.EntityManager.GetComponentObject<Transform>(newGoEntity).GetComponents(prefabDeclarers);
                        ((Transform)gameObjectWorld.EntityManager.Debug.GetComponentBoxed(newGoEntity, typeof(Transform))).GetComponents(prefabDeclarers);

                        // let each component declare any prefab refs it knows about
                        foreach (var prefabDeclarer in prefabDeclarers)
                        {
                            prefabDeclarer.DeclareReferencedPrefabs(declaredPrefabs);
                        }

                        prefabDeclarers.Clear();
                    }
                }

                // mark as seen for next loop
                gameObjectWorld.EntityManager.AddComponent <DeclaredReferenceObjectsTag>(newAllEntitiesQuery);

                foreach (var declaredPrefab in declaredPrefabs)
                {
                    mappingSystem.DeclareReferencedPrefab(declaredPrefab);
                }
                declaredPrefabs.Clear();

                // give systems a chance to declare prefabs and assets
                gameObjectWorld.GetExistingSystem <GameObjectDeclareReferencedObjectsGroup>().Update();
            }

            // clean up the markers
            gameObjectWorld.EntityManager.RemoveComponent <DeclaredReferenceObjectsTag>(gameObjectWorld.EntityManager.UniversalQuery);
        }
コード例 #2
0
        internal static Entity GameObjectToConvertedEntity(World gameObjectWorld, GameObject gameObject)
        {
            var mappingSystem = gameObjectWorld.GetExistingSystem <GameObjectConversionMappingSystem>();

            return(mappingSystem.GetPrimaryEntity(gameObject));
        }
コード例 #3
0
 public Conversion(World conversionWorld)
 {
     MappingSystem = conversionWorld.GetExistingSystem <GameObjectConversionMappingSystem>();
     MappingSystem.BeginConversion();
 }
コード例 #4
0
        /// <summary>
        /// Adds the collection of systems to the world by injecting them into the root level system groups
        /// (InitializationSystemGroup, SimulationSystemGroup and PresentationSystemGroup)
        /// </summary>
        public static void AddSystemsToRootLevelSystemGroups(World world, params Type[] systemTypes)
        {
            var initializationSystemGroup = world.GetOrCreateSystem <InitializationSystemGroup>();
            var simulationSystemGroup     = world.GetOrCreateSystem <SimulationSystemGroup>();
            var presentationSystemGroup   = world.GetOrCreateSystem <PresentationSystemGroup>();

            var systems = world.GetOrCreateSystemsAndLogException(systemTypes.ToArray());

            // Add systems to their groups, based on the [UpdateInGroup] attribute.
            foreach (var system in systems)
            {
                if (system == null)
                {
                    continue;
                }

                // Skip the built-in root-level system groups
                var type = system.GetType();
                if (type == typeof(InitializationSystemGroup) ||
                    type == typeof(SimulationSystemGroup) ||
                    type == typeof(PresentationSystemGroup))
                {
                    continue;
                }

                var groups = TypeManager.GetSystemAttributes(system.GetType(), typeof(UpdateInGroupAttribute));
                if (groups.Length == 0)
                {
                    simulationSystemGroup.AddSystemToUpdateList(system);
                }

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

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

                    var groupMgr = world.GetExistingSystem(group.GroupType);
                    if (groupMgr == null)
                    {
                        // Warn against unexpected behaviour combining DisableAutoCreation and UpdateInGroup
                        var parentDisableAutoCreation = TypeManager.GetSystemAttributes(group.GroupType, typeof(DisableAutoCreationAttribute)).Length > 0;
                        if (parentDisableAutoCreation)
                        {
                            Debug.LogWarning($"A system {type} wants to execute in {group.GroupType} but this group has [DisableAutoCreation] and {type} does not. The system will not be added to any group and thus not update.");
                        }
                        else
                        {
                            Debug.LogWarning(
                                $"A system {type} could not be added to group {group.GroupType}, because the group was not created. Fix these errors before continuing. The system will not be added to any group and thus not update.");
                        }
                        continue;
                    }

                    var groupSys = groupMgr as ComponentSystemGroup;
                    if (groupSys != null)
                    {
                        groupSys.AddSystemToUpdateList(system);
                    }
                }
            }

            // Update player loop
            initializationSystemGroup.SortSystems();
            simulationSystemGroup.SortSystems();
            presentationSystemGroup.SortSystems();
        }
 protected override void OnCreate()
 {
     base.OnCreate();
     _incremental = World.GetExistingSystem <IncrementalChangesSystem>();
 }
コード例 #6
0
        public static void InitializeSystems(World world)
        {
            var allSystemTypes = TypeManager.GetSystems();
            var allSystemNames = TypeManager.SystemNames;

            if (allSystemTypes.Length == 0)
            {
                throw new InvalidOperationException("DefaultTinyWorldInitialization: No Systems found.");
            }

            // Create top level presentation system and simulation systems.
            InitializationSystemGroup initializationSystemGroup = new InitializationSystemGroup();

            world.AddSystem(initializationSystemGroup);

            SimulationSystemGroup simulationSystemGroup = new SimulationSystemGroup();

            world.AddSystem(simulationSystemGroup);

            PresentationSystemGroup presentationSystemGroup = new PresentationSystemGroup();

            world.AddSystem(presentationSystemGroup);

            // Create the working set of systems.
            int nSystems = 0;

            Type[]            systemTypes = new Type[allSystemTypes.Length];
            ComponentSystem[] systems     = new ComponentSystem[allSystemTypes.Length];

#if WRITE_LOG
            Console.WriteLine("--- Adding systems:");
#endif

            for (int i = 0; i < allSystemTypes.Length; i++)
            {
                if (TypeManager.GetSystemAttributes(allSystemTypes[i], typeof(DisableAutoCreationAttribute)).Length > 0)
                {
                    continue;
                }
                if (allSystemTypes[i] == initializationSystemGroup.GetType() ||
                    allSystemTypes[i] == simulationSystemGroup.GetType() ||
                    allSystemTypes[i] == presentationSystemGroup.GetType())
                {
                    continue;
                }

                if (world.GetExistingSystem(allSystemTypes[i]) != null)
                {
                    continue;
                }
#if WRITE_LOG
                Console.WriteLine(allSystemNames[i]);
#endif
                systemTypes[nSystems] = allSystemTypes[i];
                systems[nSystems]     = TypeManager.ConstructSystem(allSystemTypes[i]);
                world.AddSystem(systems[nSystems]);
                nSystems++;
            }
#if WRITE_LOG
            Console.WriteLine("--- Adding systems Done.");
#endif

            for (int i = 0; i < nSystems; ++i)
            {
                var sysType = systemTypes[i];
                var system  = systems[i];

                var groups = TypeManager.GetSystemAttributes(sysType, typeof(UpdateInGroupAttribute));
                if (groups.Length == 0)
                {
                    simulationSystemGroup.AddSystemToUpdateList(system);
                }

                for (int g = 0; g < groups.Length; ++g)
                {
                    var groupType   = groups[g] as UpdateInGroupAttribute;
                    var groupSystem = world.GetExistingSystem(groupType.GroupType) as ComponentSystemGroup;
                    if (groupSystem == null)
                    {
                        throw new Exception("DefaultTinyWorldInitialization failed to find existing SystemGroup.");
                    }

                    groupSystem.AddSystemToUpdateList(system);
                }
            }
        }