Ejemplo n.º 1
0
    private void makeBait()
    {
        Unity.Entities.EntityManager eM = World.DefaultGameObjectInjectionWorld.EntityManager;
        EntityArchetype bait            = eM.CreateArchetype(
            typeof(Translation),
            typeof(RenderMesh),
            typeof(Scale),
            typeof(Rotation),
            typeof(RenderBounds),
            typeof(bait),
            typeof(LocalToWorld));
        Entity entity = eM.CreateEntity(bait);

        eM.AddComponentData(entity, new Translation
        {
            Value = new float3(0, 0, 0)
        }
                            );
        eM.SetSharedComponentData(entity, new RenderMesh
        {
            mesh     = baitMesh,
            material = baitMaterial
        }
                                  );
    }
Ejemplo n.º 2
0
    private void makeEntity(int i)
    {
        Unity.Entities.EntityManager eM = World.DefaultGameObjectInjectionWorld.EntityManager;
        EntityArchetype boid            = eM.CreateArchetype(
            typeof(Translation),
            typeof(RenderMesh),
            typeof(Scale),
            typeof(Rotation),
            typeof(RenderBounds),
            typeof(Flock_settings),
            typeof(LocalToWorld));
        Entity entity = eM.CreateEntity(boid);

        eM.AddComponentData(entity, new Translation
        {
            Value = new float3(i % 24, (int)i / 4, 0)
        }
                            );
        eM.AddComponentData(entity, new Flock_settings
        {
            direction         = new float3(0, 0, 0),
            flockHeading      = new float3(0, 0, 0),
            flockCentre       = new float3(0, 0, 0),
            separationHeading = new float3(0, 0, 0),
            velocity          = new float3(0, 0, 0),
            index             = i,
            numFlockmates     = 0
        }
                            );
        eM.SetSharedComponentData(entity, new RenderMesh
        {
            mesh     = boidMesh,
            material = boidMaterial
        }
                                  );
        eM.AddComponentData(entity, new Scale
        {
            Value = .1f
        }
                            );
    }
Ejemplo n.º 3
0
    void CreateGrid()
    {
        //Create Entity TileMap
        Cells = new Entity[GridWidth * GridHeight];

        //Make this object transform center of map
        UnityEngine.Vector3 offset = new UnityEngine.Vector3(
            this.transform.position.x - (((((float)GridWidth * CellSize)) / 2) - (CellSize / 2)),
            this.transform.position.y + (((((float)GridHeight * CellSize)) / 2) + (CellSize / 2)), 0);

        // Create Tiles
        bool isWall;
        int  index = 0;

        for (int y = 0; y < GridHeight; y++)
        {
            for (int x = 0; x < GridWidth; x++)
            {
                Entity cell;
                isWall = false;

                //Create Cell Entity
                cell = em.CreateEntity(CellArchtype);

                // Border Tiles
                if (x == 0 || y == 0 || x == GridWidth - 1 || y == GridHeight - 1)
                {
                    isWall = true;
                }

                //Calculate World Pos
                float  xpos = offset.x + (float)(x * CellSize);
                float  ypos = offset.y - (float)(y * CellSize);
                float3 pos  = new float3(xpos, ypos, 0);

                //Fill Position Data
                em.SetComponentData(cell, new Translation
                {
                    Value = pos
                });

                //Calc Neighbors Indexs
                int bottomIndex = -1;
                int topIndex    = -1;
                int leftIndex   = -1;
                int rightIndex  = -1;

                if (index - GridWidth >= 0)
                {
                    topIndex = (index - GridWidth);  // north
                }
                if (index % GridWidth != 0)
                {
                    leftIndex = (index - 1);  // west
                }

                if (((index + 1) % GridWidth) != 0)
                {
                    rightIndex = index + 1;  // east
                }

                if (index + GridWidth < Cells.Length)
                {
                    bottomIndex = (index + GridWidth);  // south
                }

                if (isWall)
                {
                    //Set CellComponent Data
                    em.SetComponentData(cell, new CellComponent
                    {
                        xGrid            = x,
                        yGrid            = y,
                        CellType         = 1, //Solid
                        SpriteSheetFrame = 2, //Wall Frame
                        worldPos         = new Unity.Mathematics.float2(xpos, ypos),
                        CellSize         = CellSize,
                        Liquid           = 0f,
                        Settled          = false,
                        index            = index,
                        LeftIndex        = leftIndex,
                        RightIndex       = rightIndex,
                        BottomIndex      = bottomIndex,
                        TopIndex         = topIndex
                    });
                }
                else
                {
                    //Set Empty Cell Data
                    em.SetComponentData(cell, new CellComponent
                    {
                        xGrid            = x,
                        yGrid            = y,
                        CellType         = 0, //NOT Solid
                        SpriteSheetFrame = 0, //Empty Frame
                        worldPos         = new Unity.Mathematics.float2(xpos, ypos),
                        CellSize         = CellSize,
                        Liquid           = 0f, //Empty
                        Settled          = false,
                        index            = index,
                        LeftIndex        = leftIndex,
                        RightIndex       = rightIndex,
                        BottomIndex      = bottomIndex,
                        TopIndex         = topIndex
                    });
                }

                //Add Cell to Array
                Cells[CalculateCellIndex(x, y, GridWidth)] = cell;
                index++;
            }
        }
    }
 public static Entity Instantiate(this EntityManager entityManager, GameObject srcGameObject)
 {
     return(entityManager.CreateEntity());
 }