Beispiel #1
0
        public void Init()
        {
            //! 随机出生点
            GameObject[] pss = GameObject.FindGameObjectsWithTag("Respawn");
            int          rnd = Random.Range(0, pss.Length);

            GameObject ps = pss[rnd];

            respawnTrans = ps.transform;
            avatarType   = GameApp.GetInstance().GetGameState().Avatar;
            //! playerObject = AvatarFactory.GetInstance().CreateAvatar(avatarType);   //! 创建角色

            playerObject = AvatarFactory.GetInstance().CreateAvatar(Zombie3D.AvatarType.EnegyArmor);               //! 创建钢铁侠
            playerObject.transform.position = ps.transform.position;
            playerObject.transform.rotation = ps.transform.rotation;

            playerObject.name = "Player";
            playerTransform   = playerObject.transform;
            playerConfig      = GameApp.GetInstance().GetGameConfig().playerConf;
            int armorLevel = GameApp.GetInstance().GetGameState().ArmorLevel;

            hp    = playerConfig.hp * (1 + armorLevel * 0.5f);
            maxHp = hp;

            //! 特种兵的血量 × 2
            if (avatarType == AvatarType.Swat)
            {
                hp    = hp * Constant.SWAT_HP;
                maxHp = hp;
            }
            else if (avatarType == AvatarType.EnegyArmor)
            {
                hp    = hp * Constant.ENEGY_ARMOR_HP_BOOST;
                maxHp = hp;
            }


            gameCamera     = GameApp.GetInstance().GetGameScene().GetCamera();
            charController = playerObject.GetComponent <CharacterController>();   //! 控制器
            animation      = playerObject.GetComponent <UnityEngine.Animation>(); //! 动画器
            collider       = playerObject.GetComponent <Collider>();              //! 碰撞检测

            //! 音效
            audioPlayer = new AudioPlayer();
            Transform folderTrans = playerTransform.Find("Audio");

            audioPlayer.AddAudio(folderTrans, AudioName.GETITEM);
            audioPlayer.AddAudio(folderTrans, AudioName.DEAD);
            audioPlayer.AddAudio(folderTrans, AudioName.SWITCH);
            audioPlayer.AddAudio(folderTrans, AudioName.WALK);


            //! 为什么又初始化一边武器列表
            GameApp.GetInstance().GetGameState().InitWeapons();


            weaponList = GameApp.GetInstance().GetGameState().GetBattleWeapons();


            playerState = Player.IDLE_STATE;



            foreach (Weapon w in weaponList)
            {
                w.Init();
            }


            Weapon powerWeapon = null;
            float  maxDamage   = 0;

            foreach (Weapon w in weaponList)
            {
                if (maxDamage < w.Damage)
                {
                    maxDamage   = w.Damage;
                    powerWeapon = w;
                }

                //! if (w.IsSelectedForBattle)
                //! {
                //!     ChangeWeapon(w);
                //!     break;
                //! }
            }

            //! 切换武器
            ChangeWeapon(powerWeapon);


            walkSpeed = GameApp.GetInstance().GetGameConfig().playerConf.walkSpeed - weapon.GetSpeedDrag();  //! 人物速度 - 武器武器负重

            ChangeToNormalState();


            if (gameCamera.GetCameraType() == CameraType.TPSCamera)
            {
                inputController = new TPSInputController();
                inputController.Init();
            }
            else if (gameCamera.GetCameraType() == CameraType.TopWatchingCamera)
            {
                inputController = new TopWatchingInputController();
                inputController.Init();
            }


            UpdateNearestWayPoint();
        }
Beispiel #2
0
        public override void NextState(Player player, float deltaTime)
        {
            InputController inputController = player.InputController;

            InputInfo inputInfo = new InputInfo();

            inputController.ProcessInput(deltaTime, inputInfo);
            player.ZoomIn(deltaTime);

            Weapon weapon = player.GetWeapon();

            if (weapon != null)
            {
                if (weapon.GetWeaponType() == WeaponType.Sniper)
                {
                    Sniper autoMissle = weapon as Sniper;
                    if (!autoMissle.HaveBullets())
                    {
                        player.SetState(Player.IDLE_STATE);
                    }
                    else
                    {
                        if (inputInfo.fire)
                        {
                            player.AutoAim(deltaTime);
                        }
                        else
                        {
                            if (autoMissle.AimedTarget())
                            {
                                player.Fire(deltaTime);
                            }
                        }
                    }
                }
                else
                {
                    if (!weapon.HaveBullets())
                    {
                        player.SetState(Player.IDLE_STATE);
                    }
                    else if (!weapon.CouldMakeNextShoot())
                    {
                        weapon.FireUpdate(deltaTime);
                    }
                    else
                    {
                        //¹¥»÷
                        if (inputInfo.fire)
                        {
                            weapon.FireUpdate(deltaTime);
                            player.Fire(deltaTime);
                            WeaponType wType = weapon.GetWeaponType();
                            switch (wType)
                            {
                            case WeaponType.ShotGun:
                            case WeaponType.RocketLauncher:
                                player.Animate(AnimationName.PLAYER_SHOT + player.WeaponNameEnd, WrapMode.Once);
                                break;

                            case WeaponType.Saw:
                                player.RandomSawAnimation();
                                player.Animate(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd, WrapMode.Loop);
                                break;

                            default:
                                player.Animate(AnimationName.PLAYER_SHOT + player.WeaponNameEnd, WrapMode.Loop);
                                break;
                            }
                        }
                    }
                }
            }


            bool isPlayingAnimation = player.IsPlayingAnimation(AnimationName.PLAYER_SHOT + player.WeaponNameEnd);
            bool animationEnds      = player.AnimationEnds(AnimationName.PLAYER_SHOT + player.WeaponNameEnd);

            if ((isPlayingAnimation && animationEnds) || !isPlayingAnimation)
            {
                if (!inputInfo.fire && !inputInfo.IsMoving())
                {
                    player.SetState(Player.IDLE_STATE);
                    player.StopFire();
                }
                else if (inputInfo.fire && inputInfo.IsMoving())
                {
                    player.SetState(Player.RUNSHOOT_STATE);
                }
                else if (!inputInfo.fire && inputInfo.IsMoving())
                {
                    player.SetState(Player.RUN_STATE);
                    player.StopFire();
                }
                else
                {
                    //¹¥»÷¼ä¸ô
                    WeaponType wType = weapon.GetWeaponType();
                    if (wType == WeaponType.AssaultRifle ||
                        weapon.GetWeaponType() == WeaponType.MachineGun ||
                        weapon.GetWeaponType() == WeaponType.LaserGun ||
                        weapon.GetWeaponType() == WeaponType.Saw
                        )
                    {
                        player.Animate(AnimationName.PLAYER_SHOT + player.WeaponNameEnd, WrapMode.Loop);
                    }
                    else
                    {
                        player.Animate(AnimationName.PLAYER_IDLE + player.WeaponNameEnd, WrapMode.Loop);
                    }
                }
            }
        }
Beispiel #3
0
        public override void NextState(Player player, float deltaTime)
        {
            InputController inputController = player.InputController;

            InputInfo inputInfo = new InputInfo();

            inputController.ProcessInput(deltaTime, inputInfo);

            player.ZoomIn(deltaTime);
            player.Move(inputInfo.moveDirection * (deltaTime * player.WalkSpeed * Constant.PLAYING_WALKINGSPEED_DISCOUNT_WHEN_SHOOTING));


            Weapon weapon = player.GetWeapon();

            if (weapon != null)
            {
                if (weapon.GetWeaponType() == WeaponType.Sniper)
                {
                    Sniper autoMissle = weapon as Sniper;
                    if (!autoMissle.HaveBullets())
                    {
                        player.SetState(Player.RUN_STATE);
                    }
                    else
                    {
                        if (inputInfo.fire)
                        {
                            autoMissle.AutoAim(deltaTime);
                            player.Animate(AnimationName.PLAYER_RUN + player.WeaponNameEnd, WrapMode.Loop);
                        }
                        else
                        {
                            if (autoMissle.AimedTarget())
                            {
                                player.Fire(deltaTime);
                                player.Animate(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd, WrapMode.Once);
                            }
                        }
                    }
                }
                else
                {
                    weapon.FireUpdate(deltaTime);
                    if (inputInfo.fire)
                    {
                        if (!weapon.HaveBullets())
                        {
                            player.SetState(Player.RUN_STATE);
                        }
                        else if (!weapon.CouldMakeNextShoot())
                        {
                            //weapon.FireUpdate(deltaTime);
                        }
                        else
                        {
                            //weapon.FireUpdate(deltaTime);
                            player.Fire(deltaTime);
                            WeaponType wType = weapon.GetWeaponType();
                            switch (wType)
                            {
                            case WeaponType.RocketLauncher:
                                player.Animate(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd, WrapMode.Once);
                                break;

                            case WeaponType.ShotGun:
                                player.Animate(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd, WrapMode.ClampForever);
                                break;

                            case WeaponType.Saw:
                                player.RandomSawAnimation();
                                player.Animate(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd, WrapMode.Loop);
                                break;

                            default:
                                player.Animate(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd, WrapMode.Loop);
                                break;
                            }
                        }
                    }
                }
            }

            bool isPlayingAnimation = player.IsPlayingAnimation(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd);
            bool animationEnds      = player.AnimationEnds(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd);

            if ((isPlayingAnimation && animationEnds) || !isPlayingAnimation)
            {
                /*
                 * if (isPlayingAnimation && animationEnds)
                 * {
                 *  Debug.Log("animation ends");
                 * }
                 * else if (!isPlayingAnimation)
                 * {
                 *  Debug.Log("animation stops");
                 * }
                 */
                if (!inputInfo.fire && !inputInfo.IsMoving())
                {
                    player.StopFire();
                    player.SetState(Player.IDLE_STATE);
                }
                else if (!inputInfo.fire && inputInfo.IsMoving())
                {
                    player.StopFire();
                    player.SetState(Player.RUN_STATE);
                }
                else if (inputInfo.fire && !inputInfo.IsMoving())
                {
                    player.SetState(Player.SHOOT_STATE);
                }
                else
                {
                    if (weapon.GetWeaponType() == WeaponType.RocketLauncher)
                    {
                        player.Animate(AnimationName.PLAYER_RUN + player.WeaponNameEnd, WrapMode.Loop);
                    }
                    else if (weapon.GetWeaponType() == WeaponType.ShotGun)
                    {
                        player.Animate(AnimationName.PLAYER_RUN02 + player.WeaponNameEnd, WrapMode.Loop);
                    }
                    else if (weapon.GetWeaponType() == WeaponType.AssaultRifle ||
                             weapon.GetWeaponType() == WeaponType.MachineGun ||
                             weapon.GetWeaponType() == WeaponType.LaserGun)
                    {
                        player.Animate(AnimationName.PLAYER_RUNFIRE + player.WeaponNameEnd, WrapMode.Loop);
                    }
                }
            }
        }