Beispiel #1
0
 public static AvatarFactory GetInstance()
 {
     if (instance == null)
     {
         instance = new AvatarFactory();
     }
     return(instance);
 }
Beispiel #2
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();
        }