/// <summary> /// registers this component with the event handler (if any) /// </summary> protected override void OnEnable() { if (FPPlayer != null) { FPPlayer.Register(this); } RefreshColliders(); }
/// <summary> /// /// </summary> protected virtual void OnEnable() { if (FPPlayer != null) { FPPlayer.Register(this); } vp_GlobalEvent <Transform, string> .Register("HUDText", OnHUDText); }
/// <summary> /// /// </summary> protected virtual void OnEnable() { if (FPPlayer != null) { FPPlayer.Register(this); } m_CurrentShooter = null; VRFirePositionFunc = () => { return(FPCamera.transform.position); }; VRFireRotationFunc = () => { return(FPCamera.transform.rotation); }; BackupWeaponSettings(); }
/// <summary> /// /// </summary> protected virtual void OnDisable() { if (m_AppQuitting) { return; } if ((m_FPControllerAccelerationBak != 0.0f) && (FPController != null)) { FPController.MotorAcceleration = m_FPControllerAccelerationBak; } FPPlayer.Unregister(this); }
/// <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(); } }
/// <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; } }
/// <summary> /// performs a number of tests to see if the player can currently teleport /// and whether the pointer object is currently pointing at a position that /// can be teleported to. if so, returns that position. if not, returns /// 'NO_DESTINATION' /// </summary> protected virtual Vector3 GetDestination() { // abort if player is dead if (FPPlayer.Dead.Active) { return(NO_DESTINATION); } // abort if player is interacting if (FPPlayer.Interactable.Get() != null) { return(NO_DESTINATION); } // abort if player can interact if (VRCrosshair != null && VRCrosshair.CanInteract) { m_NextAllowedTeleportTime = (Time.time + MinTeleportInterval); return(NO_DESTINATION); } // get where we're pointed at RaycastHit hit; Physics.Linecast( DirectionPointer.position, ((DirectionPointer.position) + (DirectionPointer.forward * 100)), out hit, ~((1 << vp_Layer.LocalPlayer) | (1 << vp_Layer.Debris) | (1 << vp_Layer.IgnoreRaycast) | (1 << vp_Layer.IgnoreBullets) | (1 << vp_Layer.Trigger) | (1 << vp_Layer.Water) | (1 << vp_Layer.Pickup))); // abort if pointing at nothing if (hit.collider == null) { return(NO_DESTINATION); } // abort if pointing at a trigger if (hit.collider.isTrigger) { return(NO_DESTINATION); } // abort if too steep float steepness = Vector3.Angle(Vector3.up, hit.normal); if (steepness > FPPlayer.GetComponent <CharacterController>().slopeLimit) { return(NO_DESTINATION); } // abort if too far if (Vector3.Distance(vp_3DUtility.HorizontalVector(FPPlayer.transform.position), vp_3DUtility.HorizontalVector(hit.point)) > MaxTeleportDistance) { return(NO_DESTINATION); } // abort if path is blocked float distance = Mathf.Max(1.0f, Vector3.Distance(vp_3DUtility.HorizontalVector(FPPlayer.transform.position), vp_3DUtility.HorizontalVector(hit.point))); Vector3 point1 = FPPlayer.transform.position + (Vector3.up * (FPPlayer.Height.Get() * 0.5f)); Vector3 point2 = point1 + Vector3.up * (FPPlayer.Height.Get() - (FPPlayer.Radius.Get() * 2)); if (Physics.CapsuleCast( point1, point2, FPPlayer.Radius.Get(), FPController.transform.forward, distance, vp_Layer.Mask.PhysicsBlockers)) { if (!(hit.collider is TerrainCollider) && (hit.transform.gameObject.layer != vp_Layer.Pickup) && (!hit.collider.isTrigger) ) // non-steep terrain, triggers and pickups are always passable { return(NO_DESTINATION); } } return(hit.point); }