Пример #1
0
        public void BufferComponentTypeCreationWorks()
        {
            var bt = ComponentType.Create <EcsIntElement>();

            Assert.AreEqual(ComponentType.AccessMode.ReadWrite, bt.AccessModeType);
            Assert.AreEqual(8, bt.BufferCapacity);
        }
    private void NetworkManager_OnDisconnect()
    {
        ComponentGroup group = GetComponentGroup(ComponentType.Create <NetworkSyncState>(), ComponentType.Create <NetworkSync>());
        ComponentDataArray <NetworkSyncState> networkSyncStateComponents = group.GetComponentDataArray <NetworkSyncState>();
        ComponentDataArray <NetworkSync>      networkSyncComponents      = group.GetComponentDataArray <NetworkSync>();
        EntityArray entities = group.GetEntityArray();

        for (int i = 0; i < entities.Length; i++)
        {
            Entity entity = entities[i];
            PostUpdateCommands.RemoveComponent <NetworkSyncState>(entity);
            if (networkSyncStateComponents[i].actorId != networkManager.LocalPlayerID && networkSyncComponents[i].authority != Authority.Scene)
            {
                PostUpdateCommands.DestroyEntity(entity);
                if (EntityManager.HasComponent <Transform>(entity))
                {
                    gameObjectsToDestroy.Add(EntityManager.GetComponentObject <Transform>(entity).gameObject);
                }
            }
            else if (EntityManager.HasComponent <NetworktAuthority>(entity))
            {
                PostUpdateCommands.RemoveComponent <NetworktAuthority>(entity);
            }
            for (int j = 0; j < RemoveComponentOnDestroyEntityMethods.Count; j++)
            {
                RemoveComponentOnDestroyEntityMethods[j].Invoke(this, entity);
            }
        }
    }
Пример #3
0
            public void Execute()
            {
                var entity = entities.CreateEntity(ComponentType.Create <EcsTestData>());

                entities.SetComponentData(entity, new EcsTestData(42));
                Assert.AreEqual(42, entities.GetComponentData <EcsTestData>(entity).value);
            }
Пример #4
0
        internal void OnAddEntity(AddEntityOp op)
        {
            var entityId = op.EntityId;

            if (worker.EntityIdToEntity.ContainsKey(entityId))
            {
                throw new InvalidSpatialEntityStateException(
                          string.Format(Errors.EntityAlreadyExistsError, entityId.Id));
            }

            Profiler.BeginSample("OnAddEntity");
            var entity = EntityManager.CreateEntity();

            EntityManager.AddComponentData(entity, new SpatialEntityId
            {
                EntityId = entityId
            });
            EntityManager.AddComponent(entity, ComponentType.Create <NewlyAddedSpatialOSEntity>());

            foreach (var AddCommandCompoent in AddAllCommandComponents)
            {
                AddCommandCompoent(entity);
            }

            WorldCommands.AddWorldCommandRequesters(World, EntityManager, entity);
            worker.EntityIdToEntity.Add(entityId, entity);
            Profiler.EndSample();
        }
Пример #5
0
    bool GetComponentData <T>(ref Entity entity, out NetworkComponent componentDataContainer) where T : struct, IComponentData
    {
        componentDataContainer = null;
        if (EntityManager.HasComponent <T>(entity))
        {
            ComponentType componentType   = ComponentType.Create <T>();
            int           numberOfMembers = reflectionUtility.GetFieldsCount(componentType.GetManagedType());

            T component = EntityManager.GetComponentData <T>(entity);
            NetworkField[]        networkMemberInfos   = reflectionUtility.GetFields(componentType);
            List <ComponentField> memberDataContainers = new List <ComponentField>();
            for (int i = 0; i < numberOfMembers; i++)
            {
                memberDataContainers.Add(new ComponentField()
                {
                    Id    = i,
                    Value = (networkMemberInfos[i] as NetworkField <T>).GetValue(component)
                });
            }


            componentDataContainer = new NetworkComponent()
            {
                TypeId = reflectionUtility.GetId(componentType),
                Fields = memberDataContainers
            };
            return(true);
        }
        return(false);
    }
        // ----------------------------------------------------
        #region // Protected Methods

        protected override void OnCreateManager()
        {
            this._playerGroup = base.GetComponentGroup(
                ComponentType.ReadOnly <PlayerTag>(),
                ComponentType.Subtractive <BulletTag>(),
                ComponentType.Create <PlayerStatus>(),
                ComponentType.Create <Destroyable>(),
                ComponentType.ReadOnly <SphereCollider2D>());
            this._enemyGroup = base.GetComponentGroup(
                ComponentType.ReadOnly <EnemyTag>(),
                ComponentType.Subtractive <BulletTag>(),
                ComponentType.Create <Destroyable>(),
                ComponentType.ReadOnly <SphereCollider2D>());

            this._playerBulletGroup = base.GetComponentGroup(
                ComponentType.ReadOnly <PlayerTag>(),
                ComponentType.ReadOnly <BulletTag>(),
                ComponentType.Create <Destroyable>(),
                ComponentType.ReadOnly <SphereCollider2D>());
            this._enemyBulletGroup = base.GetComponentGroup(
                ComponentType.ReadOnly <EnemyTag>(),
                ComponentType.ReadOnly <BulletTag>(),
                ComponentType.Create <Destroyable>(),
                ComponentType.ReadOnly <SphereCollider2D>());
        }
Пример #7
0
        public void BufferCopyFromDoesNotThrowInJob()
        {
            var archetype = m_Manager.CreateArchetype(ComponentType.Create <EcsTestData>());
            var entities  = new NativeArray <Entity>(100, Allocator.Persistent);

            m_Manager.CreateEntity(archetype, entities);

            EntityCommandBuffer cb = new EntityCommandBuffer(Allocator.Persistent);
            var handle             = new BufferCopyJob
            {
                CommandBuffer = cb.ToConcurrent(),
                Entities      = entities
            }.Schedule(100, 1);

            handle.Complete();
            cb.Playback(m_Manager);

            for (var i = 0; i < 100; ++i)
            {
                var buffer = m_Manager.GetBuffer <EcsIntElement>(entities[i]);
                Assert.AreEqual(100, buffer.Length);
            }

            cb.Dispose();
            entities.Dispose();
        }
Пример #8
0
        public void ACS_BufferHas()
        {
            CreateEntities(128);

            var group  = m_Manager.CreateComponentGroup(ComponentType.Create <EcsIntElement>());
            var chunks = group.CreateArchetypeChunkArray(Allocator.TempJob);

            group.Dispose();

            var intElements     = m_Manager.GetArchetypeChunkBufferType <EcsIntElement>(false);
            var missingElements = m_Manager.GetArchetypeChunkBufferType <EcsComplexEntityRefElement>(false);

            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk = chunks[i];

                // Test Has<T>()
                bool hasIntElements = chunk.Has(intElements);
                Assert.IsTrue(hasIntElements, "Has(EcsIntElement) should be true");
                bool hasMissingElements = chunk.Has(missingElements);
                Assert.IsFalse(hasMissingElements, "Has(EcsComplexEntityRefElement) should be false");
            }

            chunks.Dispose();
        }
Пример #9
0
    void Start()
    {
        // EntityManagerを取得
        var world = World.Active;

        entityManager = world.GetOrCreateManager <EntityManager>();

        // Prefabを作成
        prefab = entityManager.CreateEntity(
            ComponentType.Create <Position>(),          // 位置
            ComponentType.Create <Scale>(),             // サイズ
            ComponentType.Create <Velocity>(),          // 速度
            ComponentType.Create <Prefab>(),            // Prefab(これがついているEntityはSystemから無視される)
            ComponentType.Create <LifeTime>(),          // 生存時間
            ComponentType.Create <TrailBufferElement>() // これまでの位置情報の配列
            );

        entityManager.SetComponentData(prefab, new Scale {
            Value = new float3(1, 1, 1) * 0.1f
        });

        // 生存時間を設定
        entityManager.SetComponentData(prefab, new LifeTime(2));

        // Prefabに描画用のComponentを追加

        /*
         * entityManager.AddSharedComponentData(prefab, new MeshInstanceRenderer {
         *  castShadows = ShadowCastingMode.On, receiveShadows = true,
         *  material = material, mesh = mesh
         * });*/

        GpuTrailRendererSystem.Material = lineMaterial;
    }
Пример #10
0
        private static void SetArchetypes(EntityManager entityManager)
        {
            var scoreHolder = ComponentType.Create <ScoreHolder>();
            var textUI      = ComponentType.Create <TextUI>();
            var input       = ComponentType.Create <Input>();

            var playerTag = ComponentType.Create <Player>();
            var blockTag  = ComponentType.Create <Block>();

            var heading         = ComponentType.Create <Heading>();
            var position        = ComponentType.Create <Position>();
            var transformMatrix = ComponentType.Create <TransformMatrix>();

            PlayerArchetype = entityManager.CreateArchetype(
                playerTag, scoreHolder, input
                );

            BlockArchetype = entityManager.CreateArchetype(
                position, transformMatrix, heading, blockTag, textUI
                );

            FloorArchetype = entityManager.CreateArchetype(
                position, transformMatrix, heading
                );
        }
Пример #11
0
        public void ACS_Buffers()
        {
            CreateEntities(128);

            var group  = m_Manager.CreateComponentGroup(ComponentType.Create <EcsIntElement>());
            var chunks = group.CreateArchetypeChunkArray(Allocator.TempJob);

            group.Dispose();

            var intElements = m_Manager.GetArchetypeChunkBufferType <EcsIntElement>(false);

            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk    = chunks[i];
                var accessor = chunk.GetBufferAccessor(intElements);

                for (int k = 0; k < accessor.Length; ++k)
                {
                    var buffer = accessor[i];

                    for (int n = 0; n < buffer.Length; ++n)
                    {
                        if (buffer[n] != n)
                        {
                            Assert.Fail("buffer element does not have the expected value");
                        }
                    }
                }
            }

            chunks.Dispose();
        }
Пример #12
0
        // ----------------------------------------------------

        #region // Protected Methods

        protected override void OnCreateManager()
        {
            this._colliderGroup = base.GetComponentGroup(
                typeof(Transform),
                ComponentType.ReadOnly <ColliderGroupInstanceID>(),
                ComponentType.ReadOnly <ColliderGroupBlittableFieldsPtr>());

            this._sphereColliderGroup = base.GetComponentGroup(
                ComponentType.ReadOnly <SphereColliderTag>());

            this._updateCenterGroup = base.GetComponentGroup(
                typeof(Transform),
                ComponentType.Create <Center>());

            this._spriteBoneGroup = base.GetComponentGroup(
                typeof(Transform),
                ComponentType.ReadOnly <SpringBoneBlittableFieldsPtr>(),
                ComponentType.ReadOnly <Length>(),
                ComponentType.ReadOnly <LocalRotation>(),
                ComponentType.ReadOnly <BoneAxis>(),
                ComponentType.ReadOnly <ParentEntity>(),
                ComponentType.ReadOnly <CenterEntity>(),
                ComponentType.Create <Rotation>(),
                ComponentType.Create <CurrentTail>(),
                ComponentType.Create <PrevTail>());
        }
Пример #13
0
        public void OnAddEntity_should_add_entity_and_command_components()
        {
            using (var wrappedOp = WorkerOpFactory.CreateAddEntityOp(TestEntityId))
            {
                receiveSystem.OnAddEntity(wrappedOp.Op);
            }

            Assert.IsTrue(worker.TryGetEntity(new EntityId(TestEntityId), out var entity));

            var id = new SpatialEntityId(); // Default value

            Assert.DoesNotThrow(() => { id = entityManager.GetComponentData <SpatialEntityId>(entity); });
            Assert.AreEqual(TestEntityId, id.EntityId.Id);

            ComponentType[] worldCommandComponentTypes =
            {
                ComponentType.Create <WorldCommands.CreateEntity.CommandSender>(),
                ComponentType.Create <WorldCommands.DeleteEntity.CommandSender>(),
                ComponentType.Create <WorldCommands.EntityQuery.CommandSender>(),
                ComponentType.Create <WorldCommands.ReserveEntityIds.CommandSender>()
            };

            foreach (var type in worldCommandComponentTypes)
            {
                Assert.IsTrue(entityManager.HasComponent(entity, type));
            }

            Assert.IsTrue(entityManager.HasComponent(entity,
                                                     ComponentType.Create <FirstComponentDispatcher.CommandComponent>()));
            Assert.IsTrue(entityManager.HasComponent(entity,
                                                     ComponentType.Create <SecondComponentDispatcher.CommandComponent>()));
        }
Пример #14
0
        public void HasComponent()
        {
            var arrayType = ComponentType.Create <EcsIntElement>();
            var entity    = m_Manager.CreateEntity(arrayType);

            Assert.IsTrue(m_Manager.HasComponent(entity, arrayType));
        }
Пример #15
0
    private void InitializeEntities(EntityManager manager)
    {
        if (count == 0)
        {
            return;
        }
        var entities = new NativeArray <Entity>((int)count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        try
        {
            entities[0] = manager.CreateEntity(ComponentType.Create <Position>(), ComponentType.Create <MeshInstanceRenderer>(), ComponentType.Create <StartTime>(), ComponentType.Create <Velocity>(), ComponentType.Create <DanceMove>(), ComponentType.Create <DanceSystem.Tag>());
            manager.SetSharedComponentData(entities[0], meshInstanceRenderer);
            manager.SetComponentData(entities[0], new StartTime {
                Value = Time.timeSinceLevelLoad
            });
            unsafe
            {
                var rest = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Entity>(((Entity * )NativeArrayUnsafeUtility.GetUnsafePtr(entities)) + 1, entities.Length - 1, Allocator.Temp);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref rest, NativeArrayUnsafeUtility.GetAtomicSafetyHandle(entities));
#endif
                manager.Instantiate(entities[0], rest);
            }
            var rand = new Unity.Mathematics.Random((uint)DateTime.Now.Ticks);
            for (int i = 0; i < entities.Length; i++)
            {
                InitializeEntity(ref rand, manager, entities[i]);
            }
        }
        finally
        {
            entities.Dispose();
        }
    }
Пример #16
0
 protected override void OnCreateManager()
 {
     componentGroup        = GetComponentGroup(ComponentType.Create <TrailBufferElement>());
     meshInstancedArgs     = new MeshInstancedArgs();
     trailMesh             = TrailMeshGenerator.CreateMesh();
     materialPropertyBlock = new MaterialPropertyBlock();
 }
Пример #17
0
    public override void CreateCube(int x, int y)
    {
        var entity = m_entityManager.CreateEntity(
            ComponentType.Create <Position>(),
            ComponentType.Create <PureWave>(),
            ComponentType.Create <MeshInstanceRenderer>()
            );

        m_entityManager.SetComponentData(entity, new Position
        {
            Value = GetPosition(x, y) - m_centerPosition
        });

        m_entityManager.SetComponentData(entity, new PureWave
        {
            speed    = m_waveSpeed,
            distance = GetDistance(x, y)
        });

        m_entityManager.SetSharedComponentData(entity, new MeshInstanceRenderer
        {
            mesh     = m_mesh,
            material = m_material
        });
    }
Пример #18
0
        public static void Initialize(EntityManager entityManager)
        {
            worldMap = entityManager.CreateArchetype(
                ComponentType.Create <WorldMap>(),
                ComponentType.Create <Chunksmap>(),
                ComponentType.Create <MapResourcesIndex>()
                );

            mapChunk = entityManager.CreateArchetype(
                ComponentType.Create <MapChunk>(),
                ComponentType.Create <Heightmap>(),
                ComponentType.Create <Groundmap>(),
                ComponentType.Create <Bordermap>(),
                ComponentType.Create <Watermap>(),
                ComponentType.Create <Itemsmap>(),
                ComponentType.Create <ItemsTransformmap>(),
                ComponentType.Create <WorldMapRef>(),

                ComponentType.Create <Groundmesh>(),
                ComponentType.Create <Watermesh>(),
                ComponentType.Create <Bordermesh>()
                );

            createMapRequest = entityManager.CreateArchetype(
                ComponentType.Create <CreateMapRequest>()
                );
            destroyMapRequest = entityManager.CreateArchetype(
                ComponentType.Create <DestroyMapRequest>()
                );
        }
Пример #19
0
    private bool GetComponentData <T>(ref Entity entity, out ComponentDataContainer componentDataContainer) where T : struct, IComponentData
    {
        componentDataContainer = null;
        if (EntityManager.HasComponent <T>(entity))
        {
            ComponentType componentType   = ComponentType.Create <T>();
            int           numberOfMembers = reflectionUtility.GetNumberOfMembers(componentType.GetManagedType());
            ComponentDataFromEntity <NetworkSyncState> networkSyncStateEntities = EntityManager.GetComponentDataFromEntity <NetworkSyncState>();

            T component = EntityManager.GetComponentData <T>(entity);
            NetworkMemberInfo[]        networkMemberInfos   = reflectionUtility.GetNetworkMemberInfo(componentType);
            List <MemberDataContainer> memberDataContainers = new List <MemberDataContainer>();
            for (int i = 0; i < numberOfMembers; i++)
            {
                memberDataContainers.Add(new MemberDataContainer()
                {
                    MemberId = i,
                    Data     = (networkMemberInfos[i] as NetworkMemberInfo <T>).GetValue(component, networkSyncStateEntities)
                });
            }


            componentDataContainer = new ComponentDataContainer()
            {
                ComponentTypeId = reflectionUtility.GetComponentTypeID(componentType),
                MemberData      = memberDataContainers
            };
            return(true);
        }
        return(false);
    }
Пример #20
0
 protected override void OnCreateManager()
 {
     m_group = GetComponentGroup(
         ComponentType.Create <CharaMotion>(),
         ComponentType.Create <CharaDash>(),
         ComponentType.ReadOnly <PadInput>());
 }
Пример #21
0
    public void Awake()
    {
        World activeWorld = World.Active;

        PivotSystem = activeWorld.GetExistingManager <BioCrowdsPivotCorrectonatorSystemDeluxe>();
        transform   = gameObject.transform;
        if (!WindowCreated)
        {
            entityManager = World.Active.GetOrCreateManager <EntityManager>();

            WindowArchetype = entityManager.CreateArchetype(
                ComponentType.Create <Position>(),
                ComponentType.Create <Rotation>());

            Window = entityManager.CreateEntity(WindowArchetype);
            Transform t = GameObject.Find("WindowManager").transform;
            entityManager.SetComponentData(Window, new Position {
                Value = new float3(t.position.x, t.position.y, t.position.z)
            });
            entityManager.SetComponentData(Window, new Rotation {
                Value = t.transform.rotation
            });
            WindowCreated = true;
        }
        if (instance == null)
        {
            instance = this;
            // DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(instance);
        }
    }
Пример #22
0
 protected override void OnCreateManager(int capacity)
 {
     manager        = EntityManager;
     ドウリルヴェルファー     = manager.CreateArchetype(ComponentType.Create <TakenokoBullet>(), ComponentType.Create <Position>(), ComponentType.Create <Frozen>(), ComponentType.Create <Heading2D>(), ComponentType.Create <MoveSpeed>(), ComponentType.Create <DestroyEnemyOutOfBoundsSystem.Tag>());
     空蝉             = manager.CreateArchetype(ComponentType.Create <空蝉Tag>(), ComponentType.Create <LifeTime>(), ComponentType.Create <Position>(), ComponentType.Create <Heading2D>(), ComponentType.Create <MoveSpeed>(), ComponentType.Create <DestroyEnemyOutOfBoundsSystem.Tag>());
     アメイジングトレンチハンマー = manager.CreateArchetype(ComponentType.Create <アメイジングトレンチハンマーTag>(), ComponentType.Create <Position2D>());
 }
        protected override void OnCreateManager()
        {
            base.OnCreateManager();

            worker       = World.GetExistingManager <WorkerSystem>();
            updateSystem = World.GetExistingManager <ComponentUpdateSystem>();

            rigidbodyGroup = GetComponentGroup(
                ComponentType.ReadOnly <Rigidbody>(),
                ComponentType.ReadOnly <TransformInternal.Component>(),
                ComponentType.ReadOnly <SpatialEntityId>(),
                ComponentType.Create <TicksSinceLastTransformUpdate>(),
                ComponentType.Create <BufferedTransform>(),
                ComponentType.Subtractive <NewlyAddedSpatialOSEntity>(),
                ComponentType.ReadOnly <TransformInternal.ComponentAuthority>());

            transformGroup = GetComponentGroup(
                ComponentType.ReadOnly <UnityEngine.Transform>(),
                ComponentType.ReadOnly <TransformInternal.Component>(),
                ComponentType.ReadOnly <SpatialEntityId>(),
                ComponentType.Create <TicksSinceLastTransformUpdate>(),
                ComponentType.Create <BufferedTransform>(),
                ComponentType.Subtractive <NewlyAddedSpatialOSEntity>(),
                ComponentType.Subtractive <Rigidbody>(),
                ComponentType.ReadOnly <TransformInternal.ComponentAuthority>());
        }
Пример #24
0
        public void GroupSelect()
        {
            var contextEntityManager = new EntityManager();

            var entity = contextEntityManager.CreateEntity(ComponentType.Create <StructComponent>());

            contextEntityManager.AddComponent(entity, new ClassComponent(1));
            contextEntityManager.SetComponent(entity, new StructComponent(2));

            entity = contextEntityManager.CreateEntity(ComponentType.Create <ClassComponent>());
            contextEntityManager.SetComponent(entity, new ClassComponent(3));
            contextEntityManager.AddComponent(entity, new StructComponent(4));

            var group = contextEntityManager.RegisterGroup(new EntityGroup());

            Assert.NotNull(group.Entities);
            Assert.NotNull(group.Classes);
            Assert.NotNull(group.Structures);

            Assert.AreEqual(2, group.Entities.CalculatedCount);
            Assert.AreEqual(0, group.Entities[0].Id);
            Assert.AreEqual(1, group.Entities[1].Id);

            Assert.AreEqual(1, group.Classes[0].Value);
            Assert.AreEqual(2, group.Structures[0].Value);

            Assert.AreEqual(3, group.Classes[1].Value);
            Assert.AreEqual(4, group.Structures[1].Value);
        }
Пример #25
0
    void Start()
    {
        World.Active = new World("move cube");
        manager      = World.Active.CreateManager <EntityManager>();
        World.Active.CreateManager(typeof(EndFrameTransformSystem));
        World.Active.CreateManager <MeshInstanceRendererSystem>().ActiveCamera = GetComponent <Camera>();
        World.Active.CreateManager(typeof(MoveSystem));
        ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.Active);

        archetype = manager.CreateArchetype(ComponentType.Create <Position>(), ComponentType.Create <Velocity>(), ComponentType.Create <MeshInstanceRenderer>());

        var src = manager.CreateEntity(archetype);

        renderers[0].material.enableInstancing = true;
        manager.SetSharedComponentData(src, renderers[0]);
        Set(src);
        using (var _ = new NativeArray <Entity>(11450, Allocator.Temp, NativeArrayOptions.UninitializedMemory))
        {
            manager.Instantiate(src, _);
            for (int i = 0; i < _.Length; i++)
            {
                Set(_[i]);
            }
        }
    }
Пример #26
0
    // Use this for initialization
    void Start()
    {
        var entityManager = World.Active.GetOrCreateManager <EntityManager>();

        for (int i = 0; i < 5000; i++)
        {
            var objectEnity = entityManager.CreateEntity(
                ComponentType.Create <RotationSpeed>(),
                ComponentType.Create <TransformMatrix>(),
                ComponentType.Create <Rotation>(),
                ComponentType.Create <Position>(),
                ComponentType.Create <MeshFilter>(),
                ComponentType.Create <MeshInstanceRenderer>(),
                ComponentType.Create <BoxCollider>()
                );
            entityManager.SetComponentData(objectEnity, new RotationSpeed {
                Value = mySpeed, PosValue = Random.Range(-100, 100)
            });

            entityManager.SetSharedComponentData(objectEnity, new MeshInstanceRenderer
            {
                mesh     = cubeMesh,
                material = myMaterial
            });
        }
    }
Пример #27
0
            public override void OnRemoveComponent(RemoveComponentOp op)
            {
                var entity = TryGetEntityFromEntityId(op.EntityId);

                Profiler.BeginSample("Connection");

                entityManager.RemoveComponent <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component>(entity);

                if (entityManager.HasComponent <ComponentAdded <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity))
                {
                    entityManager.RemoveComponent <ComponentAdded <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity);
                }
                else if (!entityManager.HasComponent <ComponentRemoved <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >(entity))
                {
                    entityManager.AddComponent(entity, ComponentType.Create <ComponentRemoved <Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection.Component> >());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(ReceivedDuplicateComponentRemoved)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField("Component", "Improbable.Gdk.Tests.AlternateSchemaSyntax.Connection")
                                            );
                }

                Profiler.EndSample();
            }
            protected override void OnUpdate()
            {
                var geneticTrainerID = new List <GeneticTrainerIDComponentData>(10);

                EntityManager.GetAllUniqueSharedComponentData(geneticTrainerID);

                var transforms = geneticTrainerGroup.GetComponentArray <Transform>();

                for (int i = 0, length = transforms.Length; i < length; ++i)
                {
                    var geneticTrainer = transforms[i].GetComponent <GeneticTrainerComponent>();
                    deadNetworkGroup.SetFilter(geneticTrainerID[i]);                    //may need to change if more than one
                    if (deadNetworkGroup.GetEntityArray().Length != 0)
                    {
                        if (deadNetworkGroup.GetEntityArray().Length == geneticTrainer.pool.Length)
                        {
                            for (int j = 0, entityCount = deadNetworkGroup.GetEntityArray().Length; deadNetworkGroup.GetEntityArray().Length != 0;)
                            {
                                var entity = deadNetworkGroup.GetEntityArray()[j];
                                geneticTrainer.scores[deadNetworkGroup.GetComponentDataArray <PointComponentData>()[j].PointValue] = entity;
                                EntityManager.AddComponentData(entity, new ResetComponentData());
                                EntityManager.RemoveComponent(entity, ComponentType.Create <DeadComponentData>());
                            }
                        }
                    }
                }
            }
Пример #29
0
            public override void OnRemoveComponent(RemoveComponentOp op)
            {
                var entity = TryGetEntityFromEntityId(op.EntityId);

                Profiler.BeginSample("ExhaustiveSingular");

                var data = entityManager.GetComponentData <Improbable.Gdk.Tests.ExhaustiveSingular.Component>(entity);

                ExhaustiveSingular.ReferenceTypeProviders.Field3Provider.Free(data.field3Handle);
                ExhaustiveSingular.ReferenceTypeProviders.Field7Provider.Free(data.field7Handle);

                entityManager.RemoveComponent <Improbable.Gdk.Tests.ExhaustiveSingular.Component>(entity);

                if (entityManager.HasComponent <ComponentAdded <Improbable.Gdk.Tests.ExhaustiveSingular.Component> >(entity))
                {
                    entityManager.RemoveComponent <ComponentAdded <Improbable.Gdk.Tests.ExhaustiveSingular.Component> >(entity);
                }
                else if (!entityManager.HasComponent <ComponentRemoved <Improbable.Gdk.Tests.ExhaustiveSingular.Component> >(entity))
                {
                    entityManager.AddComponent(entity, ComponentType.Create <ComponentRemoved <Improbable.Gdk.Tests.ExhaustiveSingular.Component> >());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(ReceivedDuplicateComponentRemoved)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField("Component", "Improbable.Gdk.Tests.ExhaustiveSingular")
                                            );
                }

                Profiler.EndSample();
            }
Пример #30
0
        public void AddRangeWorks()
        {
            var arrayType = ComponentType.Create <EcsIntElement>();
            var entity    = m_Manager.CreateEntity(arrayType);
            var buffer    = m_Manager.GetBuffer <EcsIntElement>(entity);

            for (int i = 0; i < 7; ++i)
            {
                buffer.Add(i);
            }

            Assert.AreEqual(7, buffer.Length);

            var blah = new NativeArray <EcsIntElement>(1024, Allocator.Temp);

            for (int i = 0; i < blah.Length; ++i)
            {
                blah[i] = i;
            }

            buffer.AddRange(blah);
            blah.Dispose();

            Assert.AreEqual(1024 + 7, buffer.Length);

            for (int i = 0; i < 7; ++i)
            {
                Assert.AreEqual(i, buffer[i].Value);
            }
            for (int i = 0; i < 1024; ++i)
            {
                Assert.AreEqual(i, buffer[7 + i].Value);
            }
        }