Beispiel #1
0
    protected override void OnCreateManager()
    {
        entityManager = World.GetOrCreateManager <EntityManager>();
        simGroup      = World.GetOrCreateManager <SimulationSystemGroup>();
        presGroup     = World.GetOrCreateManager <PresentationSystemGroup>();
        Entity player = entityManager.CreateEntity(typeof(RenderMesh), typeof(LocalToWorld), typeof(Translation), typeof(Rotation), typeof(NonUniformScale));

        GameObject meshPrefab = (GameObject)Resources.Load("Meshes/player");

        entityManager.SetSharedComponentData(player, new RenderMesh {
            mesh     = meshPrefab.GetComponent <MeshFilter>().sharedMesh,
            material = meshPrefab.GetComponent <Renderer>().sharedMaterial,
        });

        NonUniformScale scale = new NonUniformScale {
            Value = meshPrefab.transform.localScale,
        };

        entityManager.SetComponentData(player, scale);

        Rotation newRotation = new Rotation {
            Value = meshPrefab.transform.rotation,
        };

        entityManager.SetComponentData(player, newRotation);
    }
Beispiel #2
0
 public virtual void Setup()
 {
     m_PreviousWorld = World.DefaultGameObjectInjectionWorld;
     mWorld          = World.DefaultGameObjectInjectionWorld = new World("NewClassWorld");
     mSimGroup       = mWorld.CreateSystem <SimulationSystemGroup>();
     mEntityManager  = mWorld.EntityManager;
 }
Beispiel #3
0
        /// <summary>
        /// Queues the ball to be destroyed at the next cycle.
        /// </summary>
        ///
        /// <remarks>
        /// If there is not ball in the kicker, this does nothing.
        /// </remarks>
        public void DestroyBall()
        {
            var entityManager       = World.DefaultGameObjectInjectionWorld.EntityManager;
            var kickerCollisionData = entityManager.GetComponentData <KickerCollisionData>(Entity);
            var ballEntity          = kickerCollisionData.BallEntity;

            if (ballEntity != Entity.Null)
            {
                _ballManager.DestroyEntity(ballEntity);
                SimulationSystemGroup.QueueAfterBallCreation(() => DestroyBall(Entity));
            }
        }
Beispiel #4
0
 public SystemAssistant(
     List <ComponentSystemBase> systems,
     World world = null,
     InitializationTime initializationTime = InitializationTime.Start)
 {
     _world   = world ?? World.DefaultGameObjectInjectionWorld;
     _systems = systems;
     _simulationSystemGroup = _world.GetOrCreateSystem <SimulationSystemGroup>();
     if (initializationTime == InitializationTime.Awake)
     {
         Initialize();
     }
 }
Beispiel #5
0
        public LatiosWorld(string name) : base(name)
        {
            BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentTag <>), typeof(IComponent));
            BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentSystemStateTag <>), typeof(IComponent));
            BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentTag <>), typeof(ICollectionComponent));
            BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentSystemStateTag <>), typeof(ICollectionComponent));

            worldGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager);
            sceneGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager);
            worldGlobalEntity.AddComponentData(new WorldGlobalTag());
            sceneGlobalEntity.AddComponentData(new SceneGlobalTag());

            m_initializationSystemGroup = GetOrCreateSystem <MyInitializationSystemGroup>();
            m_simulationSystemGroup     = GetOrCreateSystem <SimulationSystemGroup>();
            m_presentationSystemGroup   = GetOrCreateSystem <PresentationSystemGroup>();
        }
Beispiel #6
0
        public LatiosWorld(string name) : base(name)
        {
            //BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentTag<>),               typeof(IManagedComponent));
            BootstrapTools.PopulateTypeManagerWithGenerics(typeof(ManagedComponentSystemStateTag <>), typeof(IManagedComponent));
            //BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentTag<>),            typeof(ICollectionComponent));
            BootstrapTools.PopulateTypeManagerWithGenerics(typeof(CollectionComponentSystemStateTag <>), typeof(ICollectionComponent));

            worldGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager);
            sceneGlobalEntity = new ManagedEntity(EntityManager.CreateEntity(), EntityManager);
            worldGlobalEntity.AddComponentData(new WorldGlobalTag());
            sceneGlobalEntity.AddComponentData(new SceneGlobalTag());

#if UNITY_EDITOR
            EntityManager.SetName(worldGlobalEntity, "World Global Entity");
            EntityManager.SetName(sceneGlobalEntity, "Scene Global Entity");
#endif

            m_initializationSystemGroup = GetOrCreateSystem <LatiosWorldInitializationSystemGroup>();
            m_simulationSystemGroup     = GetOrCreateSystem <LatiosSimulationSystemGroup>();
            m_presentationSystemGroup   = GetOrCreateSystem <LatiosPresentationSystemGroup>();
        }
Beispiel #7
0
        private void CreateWorld()
        {
            mainWorld    = new World("main");
            World.Active = mainWorld;
            initializationSystemGroup = new InitializationSystemGroup();
            presentationSystemGroup   = new PresentationSystemGroup();
            simulationSystemGroup     = new SimulationSystemGroup();
            mainWorld.AddSystem(initializationSystemGroup);
            mainWorld.AddSystem(presentationSystemGroup);
            mainWorld.AddSystem(simulationSystemGroup);
            CreateOrAddSystem <InputSystem>(1);
            CreateOrAddSystem <ControlSystem>(1);
            CreateOrAddSystem <MovementSystem>(2);
            CreateOrAddSystem <Unity.Transforms.CopyTransformToGameObjectSystem>(1);

            entity2GameObjectMapping = new Dictionary <Entity, GameObject>();
            gameObject2EntityMapping = new Dictionary <GameObject, Entity>();
            entity2PoolMapping       = new Dictionary <Entity, ObjectPool>();
//            initializationSystemGroup.AddSystemToUpdateList(mainWorld.GetOrCreateSystem<GameStateSystem>());
            // stateMachine = new StateMachine();
        }
Beispiel #8
0
 public void Kick(float angle, float speed, float inclination = 0)
 {
     SimulationSystemGroup.QueueAfterBallCreation(() => KickXYZ(Table, Entity, angle, speed, inclination, 0, 0, 0));
 }
    public static void Initialize(string worldName, bool editorWorld)
    {
        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.GetOrCreateSystem <InitializationSystemGroup>();
        SimulationSystemGroup     simulationSystemGroup     = world.GetOrCreateSystem <SimulationSystemGroup>();
        PresentationSystemGroup   presentationSystemGroup   = world.GetOrCreateSystem <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);
    }
        protected virtual void Start()
        {
            // set up initialization group
            // ReSharper disable once UnusedVariable // not used by the bootstrapper but is one of Unity's root system groups
            InitializationSystemGroup initGroup = AddSystem(typeof(Initialization), new InitializationSystemGroup());

            SetSystemSortingEnabled(initGroup, false);

            // set up simulation systems
            SimulationSystemGroup simGroup = AddSystem(typeof(FixedUpdate), new SimulationSystemGroup());

            SetSystemSortingEnabled(simGroup, false);
            {
                AddSystem(simGroup, new SimulationDestroySystem());

                SimulationResetSystemGroup simResetGroup = AddSystem(simGroup, new SimulationResetSystemGroup());
                SetSystemSortingEnabled(simResetGroup, false);
                {
                    foreach (SystemTypeReference systemTypeReference in _simulationResetSystems)
                    {
                        GetOrCreateSystem(simResetGroup, systemTypeReference.SystemType);
                    }
                }

                AddSystem(simGroup, new PreSimulationEntityCommandBufferSystem());

                SimulationMainSystemGroup simMainGroup = AddSystem(simGroup, new SimulationMainSystemGroup());
                SetSystemSortingEnabled(simMainGroup, false);
                {
                    foreach (SystemTypeReference systemTypeReference in _mainSimulationSystems)
                    {
                        GetOrCreateSystem(simMainGroup, systemTypeReference.SystemType);
                    }
                }

                AddSystem(simGroup, new PostSimulationEntityCommandBufferSystem());
            }

            // UI interactions happen before the presentation group

            // set up presentation systems
            PresentationSystemGroup presGroup = AddSystem(typeof(Update), new PresentationSystemGroup());

            SetSystemSortingEnabled(presGroup, false);
            {
                AddSystem(presGroup, new PrePresentationEntityCommandBufferSystem());

                PresentationPreUpdateSystemGroup presPreUpdateGroup = AddSystem(presGroup, new PresentationPreUpdateSystemGroup());
                SetSystemSortingEnabled(presPreUpdateGroup, false);
                {
                    foreach (SystemTypeReference systemTypeReference in _presentationPreUpdateSystems)
                    {
                        GetOrCreateSystem(presPreUpdateGroup, systemTypeReference.SystemType);
                    }
                }

                AddSystem(presGroup, new PreManagedMonoBehaviourUpdateEntityCommandBufferSystem());
                AddSystem(presGroup, new ManagedMonoBehaviourUpdateSystem());
                AddSystem(presGroup, new PostManagedMonoBehaviourUpdateEntityCommandBufferSystem());

                PresentationPostUpdateSystemGroup presPostUpdateGroup = AddSystem(presGroup, new PresentationPostUpdateSystemGroup());
                SetSystemSortingEnabled(presPostUpdateGroup, false);
                {
                    foreach (SystemTypeReference systemTypeReference in _presentationPostUpdateSystems)
                    {
                        GetOrCreateSystem(presPostUpdateGroup, systemTypeReference.SystemType);
                    }
                }

                AddSystem(presGroup, new PostPresentationEntityCommandBufferSystem());

                AddSystem(presGroup, new PresentationDestroySystem());
                AddSystem(presGroup, new PrefabSpawnSystem(this));

                AddSystem(presGroup, new EndOfFrameEntityCommandBufferSystem());

                EndOfFrameSystemGroup endOfFrameGroup = AddSystem(presGroup, new EndOfFrameSystemGroup());
                SetSystemSortingEnabled(endOfFrameGroup, false);
                {
                    foreach (SystemTypeReference systemTypeReference in _endOfFrameSystems)
                    {
                        GetOrCreateSystem(endOfFrameGroup, systemTypeReference.SystemType);
                    }
                }
            }

            // set up archetypes
            ArchetypeProducer[] initialArchetypeProducers = _archetypeProducers.ToArray();
            _archetypeProducers.Clear();

            foreach (ArchetypeProducer archetypeProducer in initialArchetypeProducers)
            {
                AddArchetypeProducer(archetypeProducer);
            }
        }
 public void Kick()
 {
     SimulationSystemGroup.QueueAfterBallCreation(() => KickXYZ(Table, Entity, Data.Angle, Data.Speed, 0, 0, 0, 0));
 }