Ejemplo n.º 1
0
    /// <summary>
    ///
    /// </summary>
    protected override void LateUpdate()
    {
        base.LateUpdate();

        if (Time.timeScale == 0.0f)
        {
            return;
        }

        if (Player.IsFirstPerson.Get())
        {
            UpdatePosition();

            UpdateCameraPosition();

            UpdateCameraRotation();

            UpdateCameraCollision();
        }
        else
        {
            FPCamera.DoCameraCollision();
        }

        UpdateFirePosition();
    }
Ejemplo n.º 2
0
    // 生成玩家
    public void GeneratePlayer(string id, int team, int swopID, int hp)
    {
        //获取出生点
        Transform sp = GameObject.Find("SwopPoints").transform;
        Transform swopTran;

        if (team == 1)
        {
            Transform teamSwop = sp.GetChild(0);
            swopTran = teamSwop.GetChild(swopID - 1);
        }
        else
        {
            Transform teamSwop = sp.GetChild(1);
            swopTran = teamSwop.GetChild(swopID - 1);
        }

        if (swopTran == null)
        {
            Debug.LogError("GeneratePlayer出生点错误!");
            return;
        }

        //预设
        if (playerPrefabGos.Length < 2)
        {
            Debug.LogError("玩家预设数量不够");
            return;
        }

        //生成玩家实例
        GameObject tankObj = (GameObject)Instantiate(playerPrefabGos[team - 1]);

        tankObj.name = id;
        tankObj.transform.position = swopTran.position;
        tankObj.transform.rotation = swopTran.rotation;

        //列表处理
        BattleUnit bu = new BattleUnit();

        bu.player    = tankObj.GetComponent <Fps_Player>();
        bu.camp      = team;
        bu.player.hp = hp;
        unitDic.Add(id, bu);
        //玩家处理
        if (id == GameMgr._instance.id)
        {
            bu.player.playerCtrl.ctrlType = PlayerController.CtrlType.Player;
            FPCamera   fpCamera = Camera.main.GetComponent <FPCamera>();
            GameObject target   = bu.player.gameObject;
            fpCamera.SetTarget(target);
        }
        else
        {
            bu.player.playerCtrl.ctrlType = PlayerController.CtrlType.Net;
            //初始化网络同步
            bu.player.playerCtrl.InitNetCtrl();
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// runs the collision check for the camera and reacts to collisions
    /// by moving the body (but not the controller) away from collision
    /// surfaces by the same distance as the camera
    /// </summary>
    protected virtual void UpdateCameraCollision()
    {
        FPCamera.DoCameraCollision();

        if (FPCamera.CollisionVector != Vector3.zero)
        {
            Transform.position += FPCamera.CollisionVector;
        }
    }
Ejemplo n.º 4
0
    void Awake()
    {
        playerCtrl = GetComponent <PlayerController>();
        playerAnim = GetComponent <PlayerAnimation>();
        fPCamera   = Camera.main.GetComponent <FPCamera>();

        BulletRigidPoolMgr.Singleton.FindOnHandWeapon();
        weapon = BulletRigidPoolMgr.Singleton.weapon;

        controller  = GetComponent <CharacterController>();
        hitCollider = GetComponent <CapsuleCollider>();
    }
Ejemplo n.º 5
0
    /// <summary>
    /// disables a vp_FPCamera and its spring and bob system after
    /// backing up its original angle, unwielding the current weapon,
    /// stopping the controller and preventing gameplay input
    /// </summary>
    public void DisableFPCamera()
    {
        m_OriginalAngle = FPCamera.transform.eulerAngles;               // backup camera angle
        // NOTE: we can't backup camera position because controller could have moved

        m_WieldedWeapon = FPPlayer.CurrentWeaponIndex.Get(); // remember the weapon we are holding
        FPPlayer.SetWeapon.TryStart(0);                      // unwield current weapon
        FPController.Stop();                                 // stop controller
        FPPlayer.InputAllowGameplay.Set(false);              // prevent player from moving
        FPCamera.SnapSprings();                              // reset spring state to default
        FPCamera.StopSprings();                              // stop springs and zero out bob
        FPCamera.enabled = false;                            // disable vp_FPCamera
    }
Ejemplo n.º 6
0
#pragma warning restore 649

    protected override void ProcessDamageDealing()
    {
        if (muzzleFlashVFX)
        {
            muzzleFlashVFX.Play();
        }

        RaycastHit hit;

        if (!Physics.Raycast(FPCamera.transform.position, FPCamera.transform.forward, out hit, range))
        {
            var screenMiddle = FPCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)).GetPoint(1000);
            ShootProjectile(screenMiddle);
            return;
        }

        ShootProjectile(hit.point);
    }
Ejemplo n.º 7
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKey(KeyCode.Alpha1))
     {
         TPCamera.SetActive(true);
         MainCamera.SetActive(false);
         FPCamera.SetActive(false);
     }
     else if (Input.GetKey(KeyCode.Alpha2))
     {
         TPCamera.SetActive(false);
         MainCamera.SetActive(false);
         FPCamera.SetActive(true);
     }
     else if (Input.GetKey(KeyCode.Alpha3))
     {
         TPCamera.SetActive(false);
         MainCamera.SetActive(true);
         FPCamera.SetActive(false);
     }
 }
Ejemplo n.º 8
0
    /// <summary>
    /// tries to ensure there is only a single audio listener in the scene for startup,
    /// to avoid unnecessary warnings being spammed to the console (the appropriate
    /// audio listener will be enabled later)
    /// </summary>
    protected virtual void TryEnsureSingleAudioListener()
    {
#if UNITY_5_3_OR_NEWER
        AudioListener[] listeners = GameObject.FindObjectsOfType <AudioListener>();
        foreach (AudioListener a in listeners)
        {
            a.enabled = false;
        }
        AudioListener b;
        if (CenterEyeAnchor != null)
        {
            b = CenterEyeAnchor.GetComponentInChildren <AudioListener>(true);
            if (b != null)
            {
                b.enabled = true;
            }
        }
        else
        {
            b = FPCamera.GetComponentInChildren <AudioListener>(true);
            if (b != null)
            {
                b.enabled = true;
            }
        }
#else
        if (FindObjectsOfType <AudioListener>().Length > 1)
        {
            if (VRAudioListener != null)
            {
                VRAudioListener.enabled = false;
            }
            FindObjectOfType <AudioListener>().enabled = true;
        }
        else if (FindObjectsOfType <AudioListener>().Length < 1)
        {
            gameObject.AddComponent <AudioListener>();
        }
#endif
    }
Ejemplo n.º 9
0
    /// <summary>
    /// performs special position adjustment logic to make the
    /// body work well with spring-based vp_FPCamera motions
    /// without having the camera clipping the local character's
    /// body model.
    /// </summary>
    protected virtual void UpdateCameraPosition()
    {
        // nail camera to neck
        FPCamera.transform.position = m_HeadLookBones[0].transform.position;

        float lookDown = Mathf.Max(0.0f, ((Player.Rotation.Get().x - 45) / 45.0f));

        lookDown = Mathf.SmoothStep(0, 1, lookDown);

        FPCamera.transform.localPosition = new Vector3(
            FPCamera.transform.localPosition.x,
            FPCamera.transform.localPosition.y,
            FPCamera.transform.localPosition.z + lookDown * (Player.Crouch.Active ? 0.0f : LookDownForwardOffset)
            );

        // apply user-adjusted 'eye position' to camera
        FPCamera.Transform.localPosition -= EyeOffset;

        // update camera zoom
        FPCamera.ZoomOffset = (-LookDownZoomFactor * lookDown);
        FPCamera.RefreshZoom();
    }
Ejemplo n.º 10
0
    /// <summary>
    /// completely restores the UFPS player hierarchy for desktop mode play. called
    /// from this script's 'OnDisable'
    /// </summary>
    protected virtual void RestorePlayerHierarchy()
    {
        // prevent nullrefs if scene is being cleared
        if (m_AppQuitting)
        {
            return;
        }

        // don't do anything if the hierarchy hasn't been modified
        if (CenterEyeAnchor == null)
        {
            return;
        }

        // restore FPCamera
        if (FPCamera != null)
        {
            FPCamera.PositionOffset = m_FPCameraOffsetBak;

            // reenable Unity camera component
            if (FPCamera.Camera != null)
            {
                FPCamera.Camera.enabled = true;
                FPCamera.Refresh();
            }
        }

        // reactivate weapon camera (if any)
        if (WeaponCamera != null)
        {
            vp_Utility.Activate(WeaponCamera.gameObject, true);
            if (FPCamera != null)
            {
                FPCamera.SnapSprings();
                FPCamera.SnapZoom();
            }
            if (WeaponHandler != null)
            {
                if (WeaponHandler.CurrentWeapon != null)
                {
                    WeaponHandler.CurrentWeapon.ResetState();
                }
            }
            if (FPCamera != null)
            {
                FPCamera.Refresh();
            }
        }

        // reactivate player body
        // NOTE: if player body has a foot fx handler, this should reenable it
        if (BodyAnimator != null)
        {
            vp_Utility.Activate(BodyAnimator.gameObject, true);
        }

        // disable our own foot fx handler
        if (VRFootFXHandler != null)
        {
            VRFootFXHandler.enabled = false;
        }

        // reenable desktop audio listener
        if (FPPlayer != null)
        {
            AudioListener[] desktopAudioListeners = FPPlayer.GetComponentsInChildren <AudioListener>(true);
            bool            done = false;
            foreach (AudioListener a in desktopAudioListeners)
            {
                if (!done)                  // only enable a single audio listener
                {
                    a.enabled = true;
                    done      = true;
                }
            }
        }

        // disable our own audio listener
        if (VRAudioListener != null)
        {
            VRAudioListener.enabled = false;
        }

        // reenable the UFPS HUD (if any)
        if (DesktopHUD != null)
        {
            DesktopHUD.enabled = true;
        }

        // unhide the UFPS crosshair
        if (DesktopCrosshair != null)
        {
            DesktopCrosshair.Hide = false;
        }

        // reallow vp_FPInput from processing pitch and yaw
        if (FPInput != null)
        {
            FPInput.MouseLookMutePitch = false;
            FPInput.MouseLookMuteYaw   = false;
        }

        // reenable all camera motion settings
        if (FPCamera != null)
        {
            FPCamera.MuteBob          = false;
            FPCamera.MuteEarthquakes  = false;
            FPCamera.MuteShakes       = false;
            FPCamera.MuteRoll         = false;
            FPCamera.MuteFallImpacts  = false;
            FPCamera.MuteBombShakes   = false;
            FPCamera.MuteGroundStomps = false;
        }

        if (FPController != null)
        {
            FPController.PhysicsForceDamping   = m_ControllerForceDampingBak;
            FPController.PhysicsSlopeSlidiness = m_ControllerSlopeSlidinessBak;
        }

        if (FPPlayer != null)
        {
            FPPlayer.RefreshActivityStates();
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// strips and modifies the UFPS player hierarchy so it works with the various
    /// 'vp_VRCameraManager' logics. called from this script's 'OnEnable'
    /// </summary>
    protected virtual IEnumerator ModifyPlayerHierarchy()
    {
        yield return(new WaitForEndOfFrame());

        if (m_AppQuitting)
        {
            yield return(null);
        }

        // disable the Unity camera on the FPCamera gameobject because the
        // OVRCameraRig has its own cameras
        if ((FPCamera != null) && (FPCamera.Camera != null))
        {
            FPCamera.Camera.enabled = false;
        }

        if (FPController != null)
        {
            m_ControllerForceDampingBak   = FPController.PhysicsForceDamping;
            m_ControllerSlopeSlidinessBak = FPController.PhysicsSlopeSlidiness;
        }

        // disable weapon camera because it does not apply / work in VR
        if (WeaponCamera != null)
        {
            vp_Utility.Activate(WeaponCamera.gameObject, false);
            FPCamera.SnapSprings();
            FPCamera.SnapZoom();
            if (WeaponHandler.CurrentWeapon != null)
            {
                WeaponHandler.CurrentWeapon.ResetState();
            }
            FPCamera.Refresh();
        }

        // disable local player body because it does not have advanced enough IK
        // for VR (at least not until UFPS 2)
        // NOTE: this will also disable any vp_PlayerFootFXHandler placed on the body object
        if (BodyAnimator != null)
        {
            vp_Utility.Activate(BodyAnimator.gameObject, false);
        }

        // enable the VR foot fx handler (if any - placed directly on the controller object)
        if (VRFootFXHandler != null)
        {
            VRFootFXHandler.enabled = true;
        }

        // disable all audio listeners on the player and enable our own
        if (VRAudioListener != null)
        {
            VRAudioListener.enabled = true;
        }
        AudioListener[] desktopAudioListeners = FPPlayer.GetComponentsInChildren <AudioListener>(true);
        foreach (AudioListener a in desktopAudioListeners)
        {
            a.enabled = false;
        }

        // disable the UFPS HUD (if any)
        if (DesktopHUD != null)
        {
            DesktopHUD.enabled = false;
        }

        // hide the UFPS crosshair
        if (DesktopCrosshair != null)
        {
            DesktopCrosshair.Hide = true;
        }
    }
Ejemplo n.º 12
0
 // Use this for initialization
 void Start()
 {
     TPCamera.SetActive(true);
     MainCamera.SetActive(false);
     FPCamera.SetActive(false);
 }