public void Convert(Entity entity, EntityManager eManager, GameObjectConversionSystem conversionSystem)
    {
        // 1) Create Archetype
        EntityArchetype archetype = eManager.CreateArchetype(
            typeof(Position2D),
            typeof(Rotation2D),
            typeof(Scale),
            //required params
            typeof(SpriteIndex),
            typeof(SpriteSheetAnimation),
            typeof(SpriteSheetMaterial),
            typeof(SpriteSheetColor),
            typeof(SpriteMatrix),
            typeof(BufferHook)
            );

        SpriteSheetManager.RecordAnimator(animator);

        var color = Color.white;

        // 3) Populate components
        List <IComponentData> components = new List <IComponentData> {
            new Position2D {
                Value = float2.zero
            },
            new Scale {
                Value = 5
            },
            new SpriteSheetColor {
                color = new float4(color.r, color.g, color.b, color.a)
            }
        };

        // 4) Instantiate the entity
        character = SpriteSheetManager.Instantiate(archetype, components, animator);
    }
        protected override void OnCreate()
        {
            ecbSource = World.GetExistingSystem <EndSimulationEntityCommandBufferSystem>();

            // Create some test entities
            // This runs on the main thread, but it is still faster to use a command buffer
            EntityCommandBuffer creationBuffer = new EntityCommandBuffer(Allocator.Temp);
            EntityArchetype     archetype      = EntityManager.CreateArchetype(typeof(GeneralPurposeComponentA));

            for (int i = 0; i < 10000; i++)
            {
                Entity newEntity = creationBuffer.CreateEntity(archetype);
                creationBuffer.SetComponent <GeneralPurposeComponentA>
                (
                    newEntity,
                    new GeneralPurposeComponentA()
                {
                    Lifetime = i
                }
                );
            }
            //Execute the command buffer
            creationBuffer.Playback(EntityManager);
        }
    void Start()
    {
        EntityManager   entityManager   = World.Active.EntityManager;
        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof(LevelComponent),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(MoveSpeedComponent)
            );
        NativeArray <Entity> entityArray = new NativeArray <Entity>(count, Allocator.Temp);

        entityManager.CreateEntity(entityArchetype, entityArray);
        for (int i = 0; i < entityArray.Length; i++)
        {
            Entity entity = entityArray[i];
            entityManager.SetComponentData(entity, new LevelComponent()
            {
                level = UnityEngine.Random.Range(10, 20)
            });
            entityManager.SetComponentData(entity, new MoveSpeedComponent()
            {
                moveSpeed = UnityEngine.Random.Range(1f, 2f)
            });
            entityManager.SetComponentData(entity, new Translation()
            {
                Value = new float3(UnityEngine.Random.Range(-8, 8f), UnityEngine.Random.Range(-5, 5f), 0)
            });
            entityManager.SetSharedComponentData(entity, new RenderMesh
            {
                mesh     = mesh,
                material = material,
            });
        }
        entityArray.Dispose();
    }
        void OnEnable()
        {
            explosion_spawn_data_queue_ = new NativeQueue <ExplosionSpawnData>(Allocator.Persistent);

            var entity_manager = World.Active.GetOrCreateManager <EntityManager>();

            arche_type_ = entity_manager.CreateArchetype(typeof(Destroyable)
                                                         , typeof(Position)
                                                         , typeof(Rotation)
                                                         , typeof(LocalToWorld)
                                                         , typeof(Frozen)
                                                         , typeof(AlivePeriod)
                                                         , typeof(StartTime)
                                                         , typeof(MeshInstanceRenderer)
                                                         );
            Vector3[] vertices = new Vector3[4];
            Vector2[] uvs      =
            {
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(0, 1),
                new Vector2(1, 1),
            };
            int[] triangles =
            {
                0, 1, 2,
                2, 1, 3,
            };
            mesh_           = new Mesh();
            mesh_.vertices  = vertices;
            mesh_.uv        = uvs;
            mesh_.triangles = triangles;
            mesh_.bounds    = new Bounds(Vector3.zero, Vector3.one * 99999999);

            instance_ = GameObject.Find("explosion_manager").GetComponent <ECSExplosionManager>();
        }
Exemplo n.º 5
0
        public void Is_Row_Full()
        {
            var world = new World("test");

            var             manager    = world.GetOrCreateManager <EntityManager>();
            var             gridSystem = world.GetOrCreateManager <TetrisGridSystem>();
            EntityArchetype archetype  = manager.CreateArchetype(typeof(Position), typeof(Rotation), typeof(Block),
                                                                 typeof(MeshInstanceRenderer));
            var row      = -5;
            var entities = new NativeArray <Entity>(TetrisGridSystem.Width, Allocator.Temp);

            for (var i = -TetrisGridSystem.Width / 2; i < TetrisGridSystem.Width / 2; i++)
            {
                manager.CreateEntity(archetype, entities);
                manager.SetComponentData(entities[i + TetrisGridSystem.Width / 2], new Position()
                {
                    Value = new float3(i, row, 0f)
                });
            }

            Assert.True(gridSystem.IsRowFull(row));
            world.DestroyManager(gridSystem);
            world.Dispose();
        }
Exemplo n.º 6
0
    private static void CreateArchtypes(EntityManager em)
    {
        boidArchetype = em.CreateArchetype(new ComponentType[]  {
            new ComponentType(typeof(Translation)),
            new ComponentType(typeof(Rotation)),
            new ComponentType(typeof(LocalToWorld)),
            new ComponentType(typeof(Boid)),
            //new ComponentType(typeof(PhysicsCollider)),
        }
                                           );

        enemyArchetype = em.CreateArchetype(new ComponentType[] {
            new ComponentType(typeof(Translation)),
            new ComponentType(typeof(Rotation)),
            new ComponentType(typeof(LocalToWorld)),
            new ComponentType(typeof(PhysicsCollider)),
            new ComponentType(typeof(Health)),
        }
                                            );

        turretArchetype = em.CreateArchetype(new ComponentType[] {
            new ComponentType(typeof(Translation)),
            new ComponentType(typeof(Rotation)),
            new ComponentType(typeof(LocalToWorld)),
            new ComponentType(typeof(Turret)),
        }
                                             );

        bulletArchetype = em.CreateArchetype(new ComponentType[] {
            new ComponentType(typeof(Bullet)),
            new ComponentType(typeof(Translation)),
            new ComponentType(typeof(Rotation)),
            new ComponentType(typeof(LocalToWorld)),
        }
                                             );
    }
Exemplo n.º 7
0
    private void MakeEntity()
    {
        EntityManager   manager   = World.DefaultGameObjectInjectionWorld.EntityManager;
        EntityArchetype archetype = manager.CreateArchetype(
            typeof(Translation),  // x y
            typeof(Rotation),     // euler rotation
            typeof(RenderMesh),   // mesh and material
            typeof(RenderBounds), // bounding box
            typeof(LocalToWorld)  // local space to world space
            );

        Entity entity = manager.CreateEntity(archetype);

        manager.AddComponentData(entity, new Translation
        {
            Value = new float3(2f, 0f, 4f)
        });

        manager.AddSharedComponentData(entity, new RenderMesh
        {
            mesh     = unitMesh,
            material = unitMaterial
        });
    }
    protected override void OnUpdate()
    {
        EntityArchetype roadArch = roadSegmentArchitecture;

        EntityCommandBuffer.ParallelWriter ecb = entityCommandBuffer.CreateCommandBuffer().AsParallelWriter();
        Entities.ForEach((Entity entity, int entityInQueryIndex, in CubicBezier cubicBezier) =>
        {
            // Todo: IJobParallelFor
            float t   = 1.0f / cubicBezier.segments;
            float3 p1 = cubicBezier.p0;
            for (int i = 1; i <= cubicBezier.segments; i++)
            {
                float3 p2 = Evaluate(cubicBezier, t * i);
                Entity e  = ecb.CreateEntity(entityInQueryIndex, roadArch);
                ecb.SetComponent(entityInQueryIndex, e, new RoadSegment
                {
                    initial = p1,
                    final   = p2
                });
                p1 = p2;
            }
            ecb.DestroyEntity(entityInQueryIndex, entity);
        }).ScheduleParallel(Dependency).Complete(); // Do not schedule parallel. It will operate on only one element any
    }
Exemplo n.º 9
0
    public void LateUpdate()
    {
        testSize = SnapSize2Grid(gameObject.transform.localScale);
        testPos  = SnapPos2Grid(gameObject.transform.position);

        if (!SnapPos2Grid(gameObject.transform.position).Equals(originBase) || !SnapSize2Grid(gameObject.transform.localScale).Equals(sizeBase))
        {
            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;
            }
            SetWindow(SnapPos2Grid(gameObject.transform.position), SnapSize2Grid(gameObject.transform.localScale));

            quads[0].transform.localScale = new Vector3(sizeVisualize.x, sizeVisualize.y, 1f);
            quads[1].transform.localScale = new Vector3(sizeCreate.x, sizeCreate.y, 1f);
            quads[2].transform.localScale = new Vector3(sizeBase.x, sizeBase.y, 1f);

            quads[0].transform.localPosition = new Vector3(originVisualize.x + quads[0].transform.localScale.x / 2f + 1f, originVisualize.y + quads[0].transform.localScale.y / 2f + 1f, quads[0].transform.localPosition.z);
            quads[1].transform.localPosition = new Vector3(originCreate.x + quads[1].transform.localScale.x / 2f + 1f, originCreate.y + quads[1].transform.localScale.y / 2f + 1f, quads[1].transform.localPosition.z);
            quads[2].transform.localPosition = new Vector3(originBase.x + quads[2].transform.localScale.x / 2f + 1f, originBase.y + quads[2].transform.localScale.y / 2f + 1f, quads[2].transform.localPosition.z);
        }
    }
        static void Boot()
        {
            var world = new World("Example World");

            world.GetOrCreateManager <NavAgentSystem>();
            var query = world.GetOrCreateManager <NavMeshQuerySystem>();

            world.GetOrCreateManager <AnimatedRendererSystem>();
            world.GetOrCreateManager <NavAgentToPositionSyncSystem>();
            world.GetOrCreateManager <RecycleDeadSystem>();
            var targetSystem = world.GetOrCreateManager <SetTargetSystem>();

            spawner = world.GetOrCreateManager <SpawnerSystem>();
            world.GetOrCreateManager <UpdateMatrixSystem>();
            manager = world.GetOrCreateManager <EntityManager>();
            var allWorlds = new World[] { world };

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(allWorlds);
            World.Active = world;
            Unit         = manager.CreateArchetype(
                typeof(SyncPositionFromNavAgent),
                typeof(Position),
                typeof(TransformMatrix),
                typeof(Unit),
                typeof(Animated),
                typeof(AnimatedState),
                typeof(NavAgent)
                );

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            // setup navmesh query
            query.UseCache = false;
            // ArchetypeDeclarationStart - Do not remove
            // ArchetypeDeclarationStop - Do not remove
        }
Exemplo n.º 11
0
    void Start()
    {
        EntityManager   entityManager   = World.Active.EntityManager;
        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof(LevelData),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(SpeedData)
            );
        NativeArray <Entity> entityArray = new NativeArray <Entity>(totalEntities, Allocator.Temp);

        entityManager.CreateEntity(entityArchetype, entityArray);

        for (int i = 0; i < entityArray.Length; i++)
        {
            Entity entity = entityArray[i];
            entityManager.SetComponentData(entity, new LevelData()
            {
                Level = Random.Range(1, 3)
            });
            entityManager.SetComponentData(entity, new SpeedData()
            {
                Speed = Random.Range(1f, 2f)
            });
            float3 startPos = new float3(Random.Range(-8, 8f), Random.Range(-5, 5), Random.Range(0, 100));
            entityManager.SetComponentData(entity, new Translation {
                Value = startPos
            });
            entityManager.SetSharedComponentData(entity, new RenderMesh {
                mesh = entityMesh, material = entityMaterial
            });
        }

        entityArray.Dispose();
    }
Exemplo n.º 12
0
    public static void Initialize()
    {
        //Creation of all archetypes

        var entityManager = World.Active.GetOrCreateManager <EntityManager>();

        TowerArchetype = entityManager.CreateArchetype(
            typeof(Tower),
            typeof(Position),
            typeof(TransformMatrix),
            typeof(MeshInstanceRenderer));

        CreepArchetype = entityManager.CreateArchetype(
            typeof(Creep),
            typeof(Position),
            typeof(Rotation),
            typeof(TransformMatrix),
            typeof(MeshInstanceRenderer),
            typeof(NeedMoveTarget),
            typeof(MoveTarget),
            typeof(MoveSpeed));

        BulletArchetype = entityManager.CreateArchetype(
            typeof(Bullet),
            typeof(Position),
            typeof(Rotation),
            typeof(TransformMatrix),
            typeof(MeshInstanceRenderer),
            typeof(NeedMoveTarget),
            typeof(MoveTarget),
            typeof(MoveSpeed));

        WayPointArchetype = entityManager.CreateArchetype(
            typeof(WayPoint),
            typeof(Position));
    }
 public int FindSerializer(EntityArchetype arch)
 {
     if (m_PlayerStateGhostSerializer.CanSerialize(arch))
     {
         return(0);
     }
     if (m_Char_TerraformerGhostSerializer.CanSerialize(arch))
     {
         return(1);
     }
     if (m_Weapon_TerraformerGhostSerializer.CanSerialize(arch))
     {
         return(2);
     }
     if (m_GameModeGhostSerializer.CanSerialize(arch))
     {
         return(3);
     }
     if (m_TeleporterGhostSerializer.CanSerialize(arch))
     {
         return(4);
     }
     throw new ArgumentException("Invalid serializer type");
 }
Exemplo n.º 14
0
    public void Start()
    {
        var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof(LevelComponent),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(MoveSpeedComponent)
            );

        NativeArray <Entity> entities = new NativeArray <Entity>(5, Allocator.Temp);

        entityManager.CreateEntity(entityArchetype, entities);

        foreach (var entity in entities)
        {
            entityManager.SetComponentData(entity, new LevelComponent {
                Level = UnityEngine.Random.Range(10, 20)
            });
            entityManager.SetComponentData(entity, new MoveSpeedComponent {
                MoveSpeed = UnityEngine.Random.Range(1f, 3f)
            });
            entityManager.SetComponentData(entity, new Translation {
                Value = new float3(UnityEngine.Random.Range(-8f, 8f), UnityEngine.Random.Range(-5f, 5f), 0)
            });
            entityManager.SetSharedComponentData(entity, new RenderMesh
            {
                mesh     = _mesh,
                material = _material
            });
        }

        entities.Dispose();
    }
Exemplo n.º 15
0
        protected override void OnCreate()
        {
            base.OnCreate();
            _networkArchetype = EntityManager.CreateArchetype(new ComponentType(typeof(Network)),
                                                              new ComponentType(typeof(NetAdjust)));
            _query = EntityManager.CreateEntityQuery(new EntityQueryDesc
            {
                All  = new[] { new ComponentType(typeof(Connection)), },
                None = new[] { new ComponentType(typeof(NetworkGroup)) },
            });
            _entranceType       = new ComponentType(typeof(Entrance));
            _exitType           = new ComponentType(typeof(Exit));
            _indexInNetworkType = new ComponentType(typeof(IndexInNetwork));

            _outCons      = new NativeMultiHashMap <Entity, Entity>(SystemConstants.MapNodeSize, Allocator.Persistent);
            _inCons       = new NativeMultiHashMap <Entity, Entity>(SystemConstants.MapNodeSize, Allocator.Persistent);
            _conToNets    = new NativeHashMap <Entity, int>(SystemConstants.MapConnectionSize, Allocator.Persistent);
            _newCons      = new NativeQueue <Entity>(Allocator.Persistent);
            _bfsOpen      = new NativeQueue <Entity>(Allocator.Persistent);
            _networkCons  = new NativeList <Entity>(SystemConstants.MapConnectionSize, Allocator.Persistent);
            _entrances    = new NativeHashMap <Entity, int>(SystemConstants.NetworkNodeSize, Allocator.Persistent);
            _exits        = new NativeHashMap <Entity, int>(SystemConstants.NetworkNodeSize, Allocator.Persistent);
            _networkCount = 0;
        }
Exemplo n.º 16
0
    private void CreateEntities(EntityManager entityManager, EntityArchetype entityArchetype)
    {
        NativeArray <Entity> entityArray = new NativeArray <Entity>(numberOfCats, Allocator.Temp);

        entityManager.CreateEntity(entityArchetype, entityArray);

        for (int i = 0; i < entityArray.Length; i++)
        {
            Entity entity = entityArray[i];

            entityManager.SetComponentData(entity, new Rotation {
                Value = new quaternion(0, 0, 0, 1)
            });
            entityManager.SetComponentData(entity, new RotationSpeedComponent {
                rotationSpeed = GetRandomRotationSpeed()
            });
            entityManager.SetComponentData(entity, new LocalToWorld {
            });
            entityManager.SetComponentData(entity, new Translation {
                Value = GetRandomPosition()
            });
            entityManager.SetComponentData(entity, new Scale {
                Value = sizeOfCats
            });
            entityManager.SetComponentData(entity, new FallComponent {
                ceilingHeight = frontRight.transform.position.y, fallSpeed = GetFallSpeed()
            });
            entityManager.SetSharedComponentData(entity, new RenderMesh
            {
                mesh     = catMesh,
                material = catMaterial
            });
        }

        entityArray.Dispose();
    }
Exemplo n.º 17
0
    private void _CreatePlayer()
    {
        EntityManager   entityManager = World.Active.EntityManager;
        EntityArchetype terrainType   = entityManager.CreateArchetype(
            typeof(PlayerComponent),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld)
            );

        Entity entity = entityManager.CreateEntity(terrainType);

        var position = new float3(Random.Range(1, 50), 0, Random.Range(1, 50));

        entityManager.SetComponentData(entity, new Translation {
            Value = position
        });
        entityManager.SetSharedComponentData(entity, new RenderMesh {
            mesh = PlayerMesh, material = PlayerMaterial
        });

        NavMeshAgent   = GameObject.FindObjectOfType <NavMeshAgent>();
        NavMeshSurface = GameObject.FindObjectOfType <NavMeshSurface>();
    }
Exemplo n.º 18
0
        void Start()
        {
            entityManager = World.Active.EntityManager;

            npcArchetype = entityManager.CreateArchetype(
                typeof(LocalToWorld),
                typeof(Translation),
                typeof(RenderMesh),
                typeof(SpeedComponent),
                typeof(NPCTag)
                );
            targetArchetype = entityManager.CreateArchetype(
                typeof(LocalToWorld),
                typeof(Translation),
                typeof(RenderMesh),
                typeof(SpeedComponent),
                typeof(TargetTag),
                typeof(Scale)
                );

            var   orthographicSize = Camera.main.orthographicSize;
            float pixelsInUnit     = Screen.height / (orthographicSize * 2);

            maxHeight = Screen.height / pixelsInUnit / 2f;
            maxWidth  = Screen.width / pixelsInUnit / 2f;

            for (int i = 0; i < 500; i++)
            {
                CreateNpc(entityManager, npcArchetype);
            }

            for (int i = 0; i < 500; i++)
            {
                CreateTarget(entityManager, targetArchetype);
            }
        }
Exemplo n.º 19
0
        void initialize()
        {
            var mf = prefab_.GetComponent <MeshFilter>();

            mesh_ = mf.sharedMesh;
            var mr = prefab_.GetComponent <MeshRenderer>();

            material_ = mr.sharedMaterial;
            var entity_manager = Unity.Entities.World.Active.GetOrCreateManager <EntityManager>();

            player_archetype_ = entity_manager.CreateArchetype(typeof(Position)
                                                               , typeof(Rotation)
                                                               , typeof(LocalToWorld)
                                                               , typeof(Destroyable)
                                                               , typeof(RigidbodyPosition)
                                                               , typeof(SphereCollider)
                                                               , typeof(PlayerCollisionInfo)
                                                               , typeof(Player)
                                                               , typeof(PlayerController)
                                                               , typeof(PlayerControllerIndex)
                                                               , typeof(MeshInstanceRenderer)
                                                               );
            cursor_archetype_ = entity_manager.CreateArchetype(typeof(Position)
                                                               , typeof(Rotation)
                                                               , typeof(ScreenPosition)
                                                               , typeof(LocalToWorld)
                                                               , typeof(RigidbodyPosition)
                                                               , typeof(Cursor)
                                                               );
            burner_archetype_ = entity_manager.CreateArchetype(typeof(Position)
                                                               , typeof(TrailData)
                                                               , typeof(TrailPoint)
                                                               , typeof(TrailRenderer)
                                                               );
            player_spawn_idx_ = 0;
        }
Exemplo n.º 20
0
    //Pure ECS
    private void MakeEntity()
    {
        EntityManager   entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        EntityArchetype archetype     = entityManager.CreateArchetype(
            typeof(Translation),
            typeof(Rotation),
            typeof(RenderMesh),
            typeof(RenderBounds),
            typeof(LocalToWorld)
            );

        Entity myEntity = entityManager.CreateEntity(archetype);

        entityManager.AddComponentData(myEntity, new Translation
        {
            Value = new float3(0f, 2f, 0f)
        });

        entityManager.AddSharedComponentData(myEntity, new RenderMesh
        {
            mesh     = mesh,
            material = material
        });
    }
Exemplo n.º 21
0
    public static void ImportEnemy(EntityManager em, EntityArchetype enemyArchetype, InitializeSettings initSettings)
    {
        var enemyEntity = em.CreateEntity(enemyArchetype);

        em.SetComponentData(enemyEntity, initSettings.enemyStats.position);
        em.SetComponentData(enemyEntity, initSettings.enemyStats.scale);
        em.SetComponentData(enemyEntity, initSettings.enemyStats.rotation);
        em.SetComponentData(enemyEntity, new AABBCollider {
            Size = initSettings.playerStats.aabbcollider
        });
        em.SetComponentData(enemyEntity, new RigidbodyComponent {
            Mass = initSettings.playerStats.rigidbody
        });
        em.SetComponentData(enemyEntity, new Velocity {
            Value = initSettings.playerStats.velocity
        });
        em.SetComponentData(enemyEntity, new Health {
            Value = initSettings.playerStats.health
        });
        em.SetComponentData(enemyEntity, new Damage {
            Value = initSettings.playerStats.damage
        });
        em.AddSharedComponentData(enemyEntity, initSettings.enemyStats.render);
    }
        protected override void OnCreateManager()
        {
            base.OnCreateManager();

            m_Group = GetComponentGroup(new EntityArchetypeQuery
            {
                All  = new[] { ComponentType.ReadOnly <Character>() },
                None = new[] { ComponentType.ReadOnly <Destroy>(), ComponentType.ReadOnly <Disabled>() }
            });

            m_Archetype = EntityManager.CreateArchetype(
                ComponentType.ReadWrite <Character>(),
                ComponentType.ReadWrite <LocalToWorld>(),
                ComponentType.ReadWrite <Translation>(),
                ComponentType.ReadWrite <Rotation>(),
                ComponentType.ReadWrite <Child>(),
                ComponentType.ReadWrite <MovementSpeed>(),
                ComponentType.ReadWrite <RotationSpeed>(),
                ComponentType.ReadWrite <RotationSpeedModifier>(),
                ComponentType.ReadWrite <WalkSpeedModifier>(),
                ComponentType.ReadWrite <ChargeSpeedModifier>(),
                ComponentType.ReadWrite <EngageSqrRadius>(),
                ComponentType.ReadWrite <AttackDistance>(),
                ComponentType.ReadWrite <AttackAnimationDuration>(),
                ComponentType.ReadWrite <AttackDamage>(),
                ComponentType.ReadWrite <AttackSpeed>(),
                ComponentType.ReadWrite <MaxHealth>(),
                ComponentType.ReadWrite <Health>(),
                ComponentType.ReadWrite <HealthRegeneration>(),
                ComponentType.ReadWrite <ViewInfo>());

            m_DestroyAllCharactersArchetype = EntityManager.CreateArchetype(ComponentType.ReadWrite <Components.Event>(), ComponentType.ReadWrite <DestroyAllCharacters>());
            m_Random = new Random(0xABCDEF);

            RequireSingletonForUpdate <CharacterCount>();
        }
Exemplo n.º 23
0
    void CreateSoldier()
    {
        EntityArchetype tempEntity = _entityManager.CreateArchetype(
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(Collider),
            typeof(RigiBody)
            );

        Entity entity = _entityManager.CreateEntity(tempEntity);

        _entityManager.SetSharedComponentData(entity, new RenderMesh {
            mesh           = _soldierMesh,
            material       = _terrianMaterialList[Random.Range(0, _terrianMaterialList.Length - 1)],
            castShadows    = ShadowCastingMode.On,
            receiveShadows = true
        });

        _entityManager.SetComponentData(entity, new Translation {
            Value = new float3(Random.Range(5, 95), 3.5f, Random.Range(5, 95))
        });

        _entityManager.SetComponentData(entity, new RigiBody()
        {
            Velocity           = RandomVelocity(),
            collied            = false,
            colliedEnter       = false,
            colliedWithSoldier = false
        });

        _entityManager.SetComponentData(entity, new Collider {
            Size     = 1f,
            bodyType = Collider.BodyType.Soldier
        });
    }
 protected override void OnCreate()
 {
     _ecbSystem     = World.GetOrCreateSystem <EntityCommandBufferSystem>();
     _cellArchetype = EntityManager.CreateArchetype(typeof(CellData));
 }
 protected override void OnCreate()
 {
     ecbSystem = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();
     healthUpdatedEventArchetype = EntityManager.CreateArchetype(typeof(HealthUpdatedEvent));
 }
Exemplo n.º 26
0
        protected override void OnCreateManager(int capacity)
        {
            // assumming up to 10 LOD
            // this can be extended later
            a_switch2NextLodDistances     = new NativeArray <float> (10, Allocator.Persistent);
            a_switch2PreviousLodDistances = new NativeArray <float> (10, Allocator.Persistent);

            // distance, at which next LOD is triggerend
            a_switch2NextLodDistances [0] = 3;
            a_switch2NextLodDistances [1] = 7;  // not utilised atm. No more LOD (TODO)
            a_switch2NextLodDistances [2] = 11; // not utilised atm. No more LOD (TODO)

            // distance, at which previous LOD is triggerend
            a_switch2PreviousLodDistances [0] = 0.5f;  // not utilised
            a_switch2PreviousLodDistances [1] = 2.5f;
            a_switch2PreviousLodDistances [2] = 6.5f;

            // EntityCommandBuffer commandBuffer = lodBarrier.CreateCommandBuffer () ; // new EntityCommandBuffer () ;
            // EntityManager entityManager = World.Active.GetOrCreateManager <EntityManager>() ;

            archetype = EntityManager.CreateArchetype(

                // typeof (ComponentDataArray <Position>),
                // typeof (Position),
                typeof(Common.Components.Float3Component),
                //typeof (Common.Components.LodComponent),
                //typeof (SharedComponentDataArray <Common.Components.Half3SharedComponent>)
                // typeof (Common.SharedComponents.Half3SharedComponent),
                typeof(Blocks.Pattern.Components.LodTargetTag),
                typeof(Blocks.Pattern.Components.IsLodActiveTag)
                );



            // temp

            // create test target (soruce from which LOD is calculating a distance)
            Entity entity = EntityManager.CreateEntity(archetype);

            EntityManager.SetComponentData(entity, new Common.Components.Float3Component {
                f3 = new float3(0f, 0, 0f)
            });

            /*
             * // create test entities to apply LOD
             * entity = EntityManager.CreateEntity (
             *  typeof ( Position ),
             *  typeof ( Blocks.Pattern.Components.Lod010Tag ),
             *  typeof ( Blocks.Pattern.Components.IsLodActiveTag )
             * ) ;
             */

            //EntityManager.SetComponentData ( entity, new Position { Value = new float3 ( 0f, 0, 3 ) } ) ;
            //EntityManager.AddComponent ( entity, typeof ( Common.Components.EntityComponent ) ) ;

            //Common.Components.EntityComponent EntityStruct = new Common.Components.EntityComponent { entity = new Entity() } ;
            //EntityManager.SetComponentData ( entity, EntityStruct ) ;



            base.OnCreateManager(capacity);
        }
Exemplo n.º 27
0
 public static void Initialize()
 {
     entityManager = World.Active.GetOrCreateManager <EntityManager>();
     cubeArchetype = entityManager.CreateArchetype(typeof(Position), typeof(CubeMoverPure), typeof(Prefab));
 }
Exemplo n.º 28
0
 public void Awake()
 {
     entityManager  = World.Active.GetOrCreateManager <EntityManager>();
     entityTemplate = entityManager.CreateArchetype(typeof(Translation), typeof(Rotation), typeof(RenderMesh), typeof(LocalToWorld), typeof(MovementSpeed), typeof(RotationSpeed)); //added movement speed comp to archetype
 }
Exemplo n.º 29
0
 private Entity spawnEntity(EntityArchetype archetype)
 {
     return(entityManager.CreateEntity(archetype));
 }
 protected override void OnStartRunning()
 {
     base.OnStartRunning();
     archetype = EntityManager.CreateArchetype(typeof(CubePosition), typeof(Parent), typeof(Translation), typeof(Rotation), typeof(LocalToWorld),
                                               typeof(LocalToParent), typeof(RenderBounds), typeof(PerInstanceCullingTag));
 }