修改FPS控制
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[Serializable]
|
||||
public class CurveControlledBob
|
||||
{
|
||||
public float HorizontalBobRange = 0.33f;
|
||||
|
||||
public float VerticalBobRange = 0.33f;
|
||||
|
||||
public AnimationCurve Bobcurve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.5f, 1f),
|
||||
new Keyframe(1f, 0f), new Keyframe(1.5f, -1f), new Keyframe(2f, 0f));
|
||||
|
||||
public float VerticaltoHorizontalRatio = 1f;
|
||||
|
||||
private float m_CyclePositionX;
|
||||
|
||||
private float m_CyclePositionY;
|
||||
|
||||
private float m_BobBaseInterval;
|
||||
|
||||
private Vector3 m_OriginalCameraPosition;
|
||||
|
||||
private float m_Time;
|
||||
|
||||
public void Setup(Camera camera, float bobBaseInterval)
|
||||
{
|
||||
m_BobBaseInterval = bobBaseInterval;
|
||||
m_OriginalCameraPosition = camera.transform.localPosition;
|
||||
m_Time = Bobcurve[Bobcurve.length - 1].time;
|
||||
}
|
||||
|
||||
public Vector3 DoHeadBob(float speed)
|
||||
{
|
||||
float x = m_OriginalCameraPosition.x + Bobcurve.Evaluate(m_CyclePositionX) * HorizontalBobRange;
|
||||
float y = m_OriginalCameraPosition.y + Bobcurve.Evaluate(m_CyclePositionY) * VerticalBobRange;
|
||||
m_CyclePositionX += speed * Time.deltaTime / m_BobBaseInterval;
|
||||
m_CyclePositionY += speed * Time.deltaTime / m_BobBaseInterval * VerticaltoHorizontalRatio;
|
||||
if (m_CyclePositionX > m_Time)
|
||||
{
|
||||
m_CyclePositionX -= m_Time;
|
||||
}
|
||||
|
||||
if (m_CyclePositionY > m_Time)
|
||||
{
|
||||
m_CyclePositionY -= m_Time;
|
||||
}
|
||||
|
||||
return new Vector3(x, y, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 491f525f09d84899a13bf70f08f7a713
|
||||
timeCreated: 1748446274
|
||||
72
Assets/Scripts/FirstPersonController/Utility/FOVKick.cs
Normal file
72
Assets/Scripts/FirstPersonController/Utility/FOVKick.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[Serializable]
|
||||
public class FOVKick
|
||||
{
|
||||
public Camera Camera;
|
||||
|
||||
[HideInInspector] public float originalFov;
|
||||
|
||||
public float FOVIncrease = 3f;
|
||||
|
||||
public float TimeToIncrease = 1f;
|
||||
|
||||
public float TimeToDecrease = 1f;
|
||||
|
||||
public AnimationCurve IncreaseCurve;
|
||||
|
||||
public void Setup(Camera camera)
|
||||
{
|
||||
CheckStatus(camera);
|
||||
Camera = camera;
|
||||
originalFov = camera.fieldOfView;
|
||||
}
|
||||
|
||||
private void CheckStatus(Camera camera)
|
||||
{
|
||||
if (camera == null)
|
||||
{
|
||||
throw new Exception("FOVKick camera is null, please supply the camera to the constructor");
|
||||
}
|
||||
|
||||
if (IncreaseCurve == null)
|
||||
{
|
||||
throw new Exception(
|
||||
"FOVKick Increase curve is null, please define the curve for the field of view kicks");
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeCamera(Camera camera)
|
||||
{
|
||||
Camera = camera;
|
||||
}
|
||||
|
||||
public IEnumerator FOVKickUp()
|
||||
{
|
||||
float t = Mathf.Abs((Camera.fieldOfView - originalFov) / FOVIncrease);
|
||||
while (t < TimeToIncrease)
|
||||
{
|
||||
Camera.fieldOfView = originalFov + IncreaseCurve.Evaluate(t / TimeToIncrease) * FOVIncrease;
|
||||
t += Time.deltaTime;
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator FOVKickDown()
|
||||
{
|
||||
float t = Mathf.Abs((Camera.fieldOfView - originalFov) / FOVIncrease);
|
||||
while (t > 0f)
|
||||
{
|
||||
Camera.fieldOfView = originalFov + IncreaseCurve.Evaluate(t / TimeToDecrease) * FOVIncrease;
|
||||
t -= Time.deltaTime;
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
Camera.fieldOfView = originalFov;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb6289c553a943a98adf26c14b1eaf2b
|
||||
timeCreated: 1748446181
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[Serializable]
|
||||
public class LerpControlledBob
|
||||
{
|
||||
public float BobDuration;
|
||||
|
||||
public float BobAmount;
|
||||
|
||||
private float m_Offset;
|
||||
|
||||
public float Offset()
|
||||
{
|
||||
return m_Offset;
|
||||
}
|
||||
|
||||
public IEnumerator DoBobCycle()
|
||||
{
|
||||
float t2 = 0f;
|
||||
while (t2 < BobDuration)
|
||||
{
|
||||
m_Offset = Mathf.Lerp(0f, BobAmount, t2 / BobDuration);
|
||||
t2 += Time.deltaTime;
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
t2 = 0f;
|
||||
while (t2 < BobDuration)
|
||||
{
|
||||
m_Offset = Mathf.Lerp(BobAmount, 0f, t2 / BobDuration);
|
||||
t2 += Time.deltaTime;
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
m_Offset = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ff17b813690432a9da59c9ab3ceccbb
|
||||
timeCreated: 1748446293
|
||||
Reference in New Issue
Block a user