protected override void OnUpdate()
        {
            EntityCommandBuffer    commandBuffer = PostUpdateCommands;
            List <EntryPlayerAnim> listAnim      = GameManager.entitiesPlayerAnim;

            for (int i = 0; i < parentData.Length; i++)
            {
                Entity        animEntity = parentData.AnimationIdleEntities[i];
                Parent        parent     = parentData.Parent[i];
                Player        player     = parentData.Player[i];
                FaceDirection faceDir    = parentData.FaceDirection[i];

                commandBuffer.RemoveComponent <AnimationPlayerAttack1>(animEntity);

                //SET LIST
                // int dirIndex = faceDir.dirIndex;
                // float3 faceDirValue = faceDir.Value;
                PlayerAnimationState state = PlayerAnimationState.ATTACK_1;
                // int endAnimToggle = listAnim[parent.AnimIndex].EndAnimationToggle;

                EntryPlayerAnim entryPlayerAnim = listAnim[parent.AnimIndex];
                entryPlayerAnim.State = state;
                entryPlayerAnim.StartAnimationToggle = 21;

                // listAnim[parent.AnimIndex] = new EntryPlayerAnim(dirIndex, faceDirValue, state, 21, endAnimToggle);
                listAnim[parent.AnimIndex] = entryPlayerAnim;

                //SET TO PLAYER (PARENT)
                player.State         = state;
                parentData.Player[i] = player;
            }
        }
Example #2
0
        protected override void OnUpdate()
        {
            EntityCommandBuffer commandBuffer = PostUpdateCommands;

            for (int i = 0; i < parentData.Length; i++)
            {
                Entity        animEntity = parentData.AnimationIdleEntities[i];
                Parent        parent     = parentData.Parent[i];
                FaceDirection faceDir    = parentData.FaceDirection[i];

                commandBuffer.RemoveComponent <AnimationBeeIdleFly>(animEntity);
                GameManager.entitiesBeeAnim[parent.AnimIndex] = new EntryBeeAnim(faceDir.dirIndex, BeeAnimationState.IDLE_FLY);
            }
        }
        protected override void OnUpdate()
        {
            EntityCommandBuffer    commandBuffer = PostUpdateCommands;
            List <EntryPlayerAnim> listAnim      = GameManager.entitiesPlayerAnim;
            int maxPlayerAttackIndex             = GameManager.settings.maxPlayerAttackIndex;

            for (int i = 0; i < data.Length; i++)
            {
                Entity        animEntity = data.AnimationEntities[i];
                Player        player     = data.Player[i];
                MoveDirection moveDir    = data.MoveDirection[i];
                FaceDirection faceDir    = data.FaceDirection[i];
                Parent        parent     = data.Parent[i];

                // PlayerAnimationState state = player.State;
                // Vector3 direction = moveDir.Value;
                int playerStartAnimToggle = player.StartAnimationToggle;
                int playerEndAnimToggle   = player.EndAnimationToggle;
                int animIndex             = parent.AnimIndex;

                EntryPlayerAnim      entryPlayerAnim = listAnim[animIndex];
                PlayerAnimationState state           = player.State;
                int    dirIndex     = faceDir.dirIndex;
                float3 faceDirValue = faceDir.Value;

                #region START ANIMATION
                if (playerStartAnimToggle != 0)
                {
                    switch (playerStartAnimToggle)
                    {
                    case 1:
                        commandBuffer.AddComponent(animEntity, new AnimationPlayerIdleStand {
                        });

                        break;

                    case 2:
                        commandBuffer.AddComponent(animEntity, new AnimationPlayerMoveRun {
                        });

                        break;

                    case 21:
                        commandBuffer.AddComponent(animEntity, new AnimationPlayerAttack1 {
                        });
                        commandBuffer.RemoveComponent <PlayerInputDirection>(animEntity);
                        commandBuffer.RemoveComponent <PlayerInputAttack>(animEntity);

                        moveDir.Value         = float3Zero;
                        data.MoveDirection[i] = moveDir;

                        break;

                    case 22:
                        commandBuffer.AddComponent(animEntity, new AnimationPlayerAttack2 {
                        });
                        commandBuffer.RemoveComponent <PlayerInputDirection>(animEntity);
                        commandBuffer.RemoveComponent <PlayerInputAttack>(animEntity);

                        moveDir.Value         = float3Zero;
                        data.MoveDirection[i] = moveDir;

                        break;

                    case 23:
                        commandBuffer.AddComponent(animEntity, new AnimationPlayerAttack3 {
                        });
                        commandBuffer.RemoveComponent <PlayerInputDirection>(animEntity);
                        commandBuffer.RemoveComponent <PlayerInputAttack>(animEntity);

                        moveDir.Value         = float3Zero;
                        data.MoveDirection[i] = moveDir;

                        break;
                    }

                    //SET LIST
                    // int endAnimToggle = listAnim[animIndex].EndAnimationToggle;
                    entryPlayerAnim.DirIndex     = dirIndex;
                    entryPlayerAnim.FaceDirValue = faceDirValue;
                    // entryPlayerAnim.State = state;
                    // entryPlayerAnim.StartAnimationToggle = 0;

                    // listAnim[animIndex] = new EntryPlayerAnim(dirIndex, faceDirValue, state, 0, endAnimToggle);
                    listAnim[animIndex] = entryPlayerAnim;

                    //SET TO PLAYER (PARENT)
                    player.StartAnimationToggle = 0;
                    data.Player[i] = player;
                }
                #endregion

                #region END ANIMATION
                if (playerEndAnimToggle != 0)
                {
                    switch (playerEndAnimToggle)
                    {
                    case 1:
                        commandBuffer.AddComponent(animEntity, new AnimationPlayerIdleStand {
                        });

                        player.AttackIndex = 0;
                        data.Player[i]     = player;

                        break;

                    case 2:
                        commandBuffer.AddComponent(animEntity, new PlayerInputDirection {
                        });
                        commandBuffer.AddComponent(animEntity, new PlayerInputAttack {
                        });

                        int attackIndex = player.AttackIndex >= maxPlayerAttackIndex ? 0 : player.AttackIndex + 1;
                        player.AttackIndex = attackIndex;
                        data.Player[i]     = player;

                        break;
                    }

                    //SET LIST
                    // int startAnimToggle = listAnim[animIndex].StartAnimationToggle;
                    entryPlayerAnim.State = state;
                    entryPlayerAnim.EndAnimationToggle = 0;

                    // listAnim[animIndex] = new EntryPlayerAnim(dirIndex, faceDirValue, state, startAnimToggle, 0);
                    listAnim[animIndex] = entryPlayerAnim;

                    //SET TO PLAYER (PARENT)
                    player.EndAnimationToggle = 0;
                    data.Player[i]            = player;
                }
                #endregion
            }
        }
Example #4
0
        protected override void OnUpdate()
        {
            EntityCommandBuffer commandBuffer = PostUpdateCommands;
            JavataleSettings    settings      = GameManager.settings;
            Mesh playerAttackMesh             = settings.playerAttackMesh;

            Material[]    playerAttackMaterials = settings.playerAttackMaterials;
            List <float3> listPos = GameManager.entitiesPos;
            List <EntryProjectileAnim> listProjectileAnim = GameManager.entitiesProjectileAnim;

            List <int> emptyPosIndexes            = GameManager.emptyPosIndexes;
            List <int> emptyProjectileAnimIndexes = GameManager.emptyProjectileAnimIndexes;

            for (int i = 0; i < data.Length; i++)
            {
                PlayerAttackSpawnData playerAttackSpawnData = data.PlayerAttackSpawnData[i];
                Entity playerAttackEntity = data.PlayerAttackEntities[i];

                commandBuffer.RemoveComponent <PlayerAttackSpawnData>(playerAttackEntity);

                Position      attackInitPos     = playerAttackSpawnData.pos;
                Rotation      attackInitRot     = playerAttackSpawnData.rot;
                MoveDirection attackInitMoveDir = playerAttackSpawnData.moveDir;
                FaceDirection attackInitFaceDir = playerAttackSpawnData.faceDir;
                Parent        attackParent      = playerAttackSpawnData.parent;
                int           attackIndex       = playerAttackSpawnData.attackIndex;

                commandBuffer.AddComponent(playerAttackEntity, attackInitPos);
                commandBuffer.AddComponent(playerAttackEntity, attackInitRot);
                commandBuffer.AddComponent(playerAttackEntity, attackInitMoveDir);
                commandBuffer.AddComponent(playerAttackEntity, attackInitFaceDir);
                commandBuffer.AddComponent(playerAttackEntity, attackParent);
                commandBuffer.AddSharedComponent(playerAttackEntity, new MeshInstanceRenderer {
                    mesh     = playerAttackMesh,
                    material = playerAttackMaterials[attackIndex]
                });

                #region POS LIST
                float3 attackPosValue      = attackInitPos.Value;
                int    currentPosListIndex = 0;

                if (emptyPosIndexes.Count > 0)
                {
                    //Get empty index from their list, then remove it
                    int emptyPosIndex = emptyPosIndexes[0];
                    emptyPosIndexes.RemoveAt(0);

                    //Set projectile list by its empty index
                    listPos[emptyPosIndex] = attackPosValue;

                    //Set current index by its empty index
                    currentPosListIndex = emptyPosIndex;
                }
                else
                {
                    listPos.Add(attackPosValue);

                    currentPosListIndex = listPos.Count - 1;
                }
                #endregion

                #region ANIM LIST
                int    attackFaceDirIndex   = attackInitFaceDir.dirIndex;
                float3 attackFaceValue      = attackInitFaceDir.Value;
                int    currentAnimListIndex = 0;

                if (emptyProjectileAnimIndexes.Count > 0)
                {
                    //Get empty index from their list, then remove it
                    int emptyProjectileAnimIndex = emptyProjectileAnimIndexes[0];
                    emptyProjectileAnimIndexes.RemoveAt(0);

                    //Set projectile list by its empty index
                    listProjectileAnim[emptyProjectileAnimIndex] = new EntryProjectileAnim(attackFaceDirIndex, attackFaceValue, 1, 0);

                    //Set current index by its empty index
                    currentAnimListIndex = emptyProjectileAnimIndex;
                }
                else
                {
                    listProjectileAnim.Add(new EntryProjectileAnim(attackFaceDirIndex, attackFaceValue, 1, 0));

                    currentAnimListIndex = listProjectileAnim.Count - 1;
                }
                #endregion

                commandBuffer.SetComponent <Parent>(playerAttackEntity, new Parent {
                    PosIndex  = currentPosListIndex,
                    AnimIndex = currentAnimListIndex
                });

                GameObject attackGO = GameObject.Instantiate(settings.playerAttack1Childs[attackIndex], attackPosValue, quaternion.identity);
                attackGO.GetComponent <ChildComponent>().PosIndex  = currentPosListIndex;
                attackGO.GetComponent <ChildComponent>().AnimIndex = currentAnimListIndex;

                // GameDebug.Log("currentPosListIndex "+currentPosListIndex+"\n attackPosValue "+attackPosValue);
                attackGO.SetActive(true);
            }
        }
Example #5
0
        static void AddEnemy(int enemyCount)
        {
            EntityManager manager = World.Active.GetOrCreateManager <EntityManager>();

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

            manager.CreateEntity(beeEnemyArchetype, entities);

            float3  float3Zero            = float3.zero;
            float   horBound              = settings.horizontalBound;
            float   verBound              = settings.verticalBound;
            float   enemyMoveSpeed        = settings.enemyMoveSpeed;
            Vector3 worldToCameraRotation = settings.worldToCameraRotation;

            for (int i = 0; i < enemyCount; i++)
            {
                float  xVal            = UnityRandom.Range(-horBound, horBound);
                float  zVal            = UnityRandom.Range(-verBound, verBound);
                float  randomIdleTimer = UnityRandom.Range(settings.enemyMinIdleCooldown, settings.enemyMaxIdleCooldown);
                float3 randomMoveDir   = new float3(UnityRandom.Range(-1, 2) == 0 ? 1f : -1f, 0f, UnityRandom.Range(-1, 2) == 0 ? 1f : -1f);

                manager.SetComponentData(entities[i], new Bee {
                    State = BeeAnimationState.IDLE_FLY, AnimationToggle = 1
                });
                manager.SetComponentData(entities[i], new EnemyAI {
                    IdleTimer = randomIdleTimer, PatrolTimer = 0f
                });
                manager.SetComponentData(entities[i], new Position {
                    Value = new float3(xVal, 0f, zVal)
                });
                manager.SetComponentData(entities[i], new Rotation {
                    Value = Quaternion.Euler(worldToCameraRotation)
                });
                manager.SetComponentData(entities[i], new MoveDirection {
                    Value = float3Zero
                });
                manager.SetComponentData(entities[i], new FaceDirection {
                    Value = randomMoveDir, dirIndex = 1
                });
                manager.SetComponentData(entities[i], new MoveSpeed {
                    Value = enemyMoveSpeed
                });

                // manager.SetSharedComponentData(entities[i],
                // new MeshInstanceRenderer
                // {
                //  mesh = settings.enemyMesh,
                //  material = settings.enemyMaterial
                // });

                #region POSITION LIST
                Position   enemyInitPos = manager.GetComponentData <Position>(entities[i]);
                GameObject enemyGO      = GameObject.Instantiate(settings.beeEnemyChild, enemyInitPos.Value, quaternion.identity);

                entitiesPos.Add(enemyInitPos.Value);                 //Add Entity Position to List

                int currentPosListIndex = entitiesPos.Count - 1;     //Get last List Index

                //Set last Pos List Index to parent and its child
                // manager.SetComponentData(entities[i], new Parent { PosIndex = currentPosListIndex });
                enemyGO.GetComponent <ChildComponent>().PosIndex = currentPosListIndex;
                #endregion

                #region ANIMATION LIST
                FaceDirection enemyInitDir = manager.GetComponentData <FaceDirection>(entities[i]);

                entitiesBeeAnim.Add(new EntryBeeAnim(enemyInitDir.dirIndex, BeeAnimationState.IDLE_FLY)); //Add Entity Animation State to List

                int currentAnimListIndex = entitiesBeeAnim.Count - 1;                                     //Get last List Index to Anim List

                //Set last Anim List Index to parent and its child
                enemyGO.GetComponent <ChildComponent>().AnimIndex = currentAnimListIndex;
                #endregion

                manager.SetComponentData(entities[i], new Parent {
                    PosIndex = currentPosListIndex, AnimIndex = currentAnimListIndex
                });
            }

            entities.Dispose();
        }
Example #6
0
        static void AddPlayer()
        {
            EntityManager manager = World.Active.GetOrCreateManager <EntityManager>();

            Entity playerEntity = manager.CreateEntity(playerArchetype);

            float3 float3Zero = float3.zero;

            manager.SetComponentData(playerEntity, new Player {
                State = PlayerAnimationState.IDLE_STAND, StartAnimationToggle = 1, EndAnimationToggle = 0
            });
            manager.SetComponentData(playerEntity, new PlayerInputDirection {
                Value = float3Zero
            });
            manager.SetComponentData(playerEntity, new Position {
                Value = float3Zero
            });
            manager.SetComponentData(playerEntity, new Rotation {
                Value = Quaternion.Euler(settings.worldToCameraRotation)
            });
            manager.SetComponentData(playerEntity, new MoveDirection {
                Value = float3Zero
            });
            manager.SetComponentData(playerEntity, new FaceDirection {
                Value = float3Zero, dirIndex = 0
            });
            manager.SetComponentData(playerEntity, new MoveSpeed {
                Value = settings.playerMoveSpeed
            });

            // manager.SetSharedComponentData(playerEntity,
            // new MeshInstanceRenderer
            // {
            //  mesh = settings.playerMesh,
            //  material = settings.playerMaterial
            // });

            #region POS LIST
            Position playerInitPos = manager.GetComponentData <Position>(playerEntity);

            entitiesPos.Add(playerInitPos.Value);             //Add Entity Position to Pos List

            int currentPosListIndex = entitiesPos.Count - 1;  //Get last List Index
            #endregion

            #region ANIM LIST
            FaceDirection playerInitFaceDir = manager.GetComponentData <FaceDirection>(playerEntity);

            //Add Entity Animation State to List (AnimationToggle = 1)
            entitiesPlayerAnim.Add(new EntryPlayerAnim(playerInitFaceDir.dirIndex, playerInitFaceDir.Value, PlayerAnimationState.IDLE_STAND, 1, 0));

            int currentAnimListIndex = entitiesPlayerAnim.Count - 1;           //Get last List Index to Anim List
            #endregion

            //Set last Pos and Anim List Index to parent and its child
            manager.SetComponentData(playerEntity, new Parent {
                PosIndex = currentPosListIndex, AnimIndex = currentAnimListIndex
            });

            GameObject playerGO = GameObject.Instantiate(settings.playerChild, playerInitPos.Value, quaternion.identity);
            playerGO.GetComponent <ChildComponent>().PosIndex  = currentPosListIndex;
            playerGO.GetComponent <ChildComponent>().AnimIndex = currentAnimListIndex;
        }