update
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Invector.vCharacterController;
|
||||
using Invector;
|
||||
using Invector.vCharacterController;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using OnlyScove.Scripts;
|
||||
|
||||
namespace Invector.vCamera
|
||||
{
|
||||
@@ -28,6 +30,19 @@ namespace Invector.vCamera
|
||||
#region inspector properties
|
||||
|
||||
public Transform mainTarget;
|
||||
public InputReader inputReader;
|
||||
|
||||
[Header("First Person View")]
|
||||
public Transform fpvTarget;
|
||||
[SerializeField] protected float fpvFOV = 80f;
|
||||
[SerializeField] protected float transitionDuration = 0.3f;
|
||||
|
||||
[Header("Modular Features")]
|
||||
[SerializeField] protected CameraCharacterFading characterFading = new CameraCharacterFading();
|
||||
[SerializeField] protected CameraOcclusionTransparency occlusionTransparency = new CameraOcclusionTransparency();
|
||||
[SerializeField] protected CameraDynamicFOV dynamicFOV = new CameraDynamicFOV();
|
||||
[SerializeField] protected CameraShakeManager shakeManager = new CameraShakeManager();
|
||||
|
||||
[Tooltip("Lerp speed between Camera States")]
|
||||
[SerializeField] protected float _smoothBetweenState = 6f;
|
||||
public virtual float smoothBetweenState { get { return _smoothBetweenState; } set { _smoothBetweenState = value; } }
|
||||
@@ -195,10 +210,56 @@ namespace Invector.vCamera
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (inputReader != null)
|
||||
{
|
||||
inputReader.OnToggleViewEvent += ToggleCameraView;
|
||||
inputReader.OnSwitchSideEvent += ToggleSwitchSide;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
if (inputReader != null)
|
||||
{
|
||||
inputReader.OnToggleViewEvent -= ToggleCameraView;
|
||||
inputReader.OnSwitchSideEvent -= ToggleSwitchSide;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ToggleSwitchSide()
|
||||
{
|
||||
SwitchRight(switchRight > 0);
|
||||
}
|
||||
|
||||
public virtual void ToggleCameraView()
|
||||
{
|
||||
if (currentState.cameraMode == TPCameraMode.FirstPerson)
|
||||
{
|
||||
ChangeState("Default");
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeState("FirstPerson");
|
||||
// If the state "FirstPerson" does not exist in the list,
|
||||
// we force the mode to FirstPerson anyway
|
||||
if (currentStateName != "FirstPerson")
|
||||
{
|
||||
currentState.cameraMode = TPCameraMode.FirstPerson;
|
||||
currentStateName = "FirstPerson";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TriggerFallImpactShake(float fallHeight)
|
||||
{
|
||||
shakeManager.TriggerFallImpactShake(fallHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init camera.
|
||||
/// </summary>
|
||||
@@ -209,6 +270,9 @@ namespace Invector.vCamera
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputReader == null) inputReader = mainTarget.GetComponent<InputReader>();
|
||||
if (inputReader == null) inputReader = GameObject.FindObjectOfType<InputReader>();
|
||||
|
||||
firstUpdated = true;
|
||||
useSmooth = true;
|
||||
targetLookAt.rotation = startUsingTargetRotation ? mainTarget.rotation : transform.rotation;
|
||||
@@ -256,6 +320,8 @@ namespace Invector.vCamera
|
||||
currentTargetPos = new Vector3(currentTarget.position.x, currentTarget.position.y + offSetPlayerPivot, currentTarget.position.z) + currentTarget.transform.up * lerpState.height;
|
||||
targetLookAt.position = currentTargetPos;
|
||||
|
||||
dynamicFOV.Initialize(currentState.fov, fpvFOV);
|
||||
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
@@ -292,7 +358,19 @@ namespace Invector.vCamera
|
||||
case TPCameraMode.FixedPoint:
|
||||
CameraFixed();
|
||||
break;
|
||||
case TPCameraMode.FirstPerson:
|
||||
CameraMovement();
|
||||
break;
|
||||
}
|
||||
|
||||
// Modular Features
|
||||
if (inputReader != null)
|
||||
{
|
||||
dynamicFOV.HandleDynamicFOV(targetCamera, inputReader,
|
||||
currentState.cameraMode == TPCameraMode.FirstPerson ? CameraController.CameraViewMode.FirstPerson : CameraController.CameraViewMode.ThirdPerson);
|
||||
}
|
||||
shakeManager.HandleShake();
|
||||
transform.position += shakeManager.ShakeOffset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -799,6 +877,12 @@ namespace Invector.vCamera
|
||||
currentState.CopyState(lerpState);
|
||||
}
|
||||
|
||||
if (currentState.cameraMode == TPCameraMode.FirstPerson)
|
||||
{
|
||||
HandleFirstPersonMovement();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentState.useZoom)
|
||||
{
|
||||
currentZoom = Mathf.Clamp(currentZoom, currentState.minDistance, currentState.maxDistance);
|
||||
@@ -918,9 +1002,44 @@ namespace Invector.vCamera
|
||||
_euler.z = 0;
|
||||
var _rot = Quaternion.Euler(_euler + currentState.rotationOffSet);
|
||||
selfRigidbody.MoveRotation(Quaternion.Lerp(startRotation, _rot, transformWeight));
|
||||
|
||||
// Apply Fading and Transparency
|
||||
characterFading.HandleCharacterFading(distance);
|
||||
occlusionTransparency.HandleTransparency(transform, targetPos);
|
||||
|
||||
movementSpeed = Vector2.zero;
|
||||
}
|
||||
|
||||
protected virtual void HandleFirstPersonMovement()
|
||||
{
|
||||
if (fpvTarget == null) return;
|
||||
|
||||
distance = 0;
|
||||
targetCamera.fieldOfView = fpvFOV;
|
||||
|
||||
// Position
|
||||
current_cPos = fpvTarget.position;
|
||||
targetLookAt.position = current_cPos;
|
||||
selfRigidbody.MovePosition(current_cPos);
|
||||
|
||||
// Rotation
|
||||
float _mouseY = Mathf.LerpAngle(mouseYStart, mouseY, transformWeight);
|
||||
float _mouseX = Mathf.LerpAngle(mouseXStart, mouseX, transformWeight);
|
||||
Quaternion newRot = Quaternion.Euler(_mouseY + offsetMouse.y, _mouseX + offsetMouse.x, 0);
|
||||
targetLookAt.rotation = useSmooth ? Quaternion.Lerp(targetLookAt.rotation, newRot, smoothCameraRotation * Time.fixedDeltaTime) : newRot;
|
||||
|
||||
selfRigidbody.MoveRotation(targetLookAt.rotation);
|
||||
|
||||
// Sync player body rotation (Yaw only)
|
||||
if (mainTarget != null)
|
||||
{
|
||||
mainTarget.rotation = Quaternion.Euler(0, targetLookAt.eulerAngles.y, 0);
|
||||
}
|
||||
|
||||
characterFading.HandleCharacterFading(0); // Fully hide character head if desired, or set to distance 0 for full hidden
|
||||
occlusionTransparency.HandleTransparency(transform, fpvTarget.position);
|
||||
}
|
||||
|
||||
protected virtual void CameraFixed()
|
||||
{
|
||||
if (useSmooth)
|
||||
|
||||
Reference in New Issue
Block a user