285 lines
7.2 KiB
C#
285 lines
7.2 KiB
C#
using Cinemachine;
|
|
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
///玩家_相机
|
|
/// </summary>
|
|
public partial class Player
|
|
{
|
|
/// <summary>
|
|
/// 震动时间
|
|
/// </summary>
|
|
private float shakeTime = 0;
|
|
|
|
/// <summary>
|
|
/// 震动速度
|
|
/// </summary>
|
|
private float lessSpeed = 1;
|
|
|
|
/// <summary>
|
|
/// 大厅相机
|
|
/// </summary>
|
|
public CinemachineVirtualCamera hallCamear;
|
|
|
|
/// <summary>
|
|
/// 商店相机
|
|
/// </summary>
|
|
public CinemachineVirtualCamera shopCamear;
|
|
|
|
/// <summary>
|
|
/// 游戏相机
|
|
/// </summary>
|
|
public CinemachineVirtualCamera gameCamear;
|
|
|
|
/// <summary>
|
|
/// 胜利相机
|
|
/// </summary>
|
|
public CinemachineVirtualCamera winCamear;
|
|
|
|
/// <summary>
|
|
/// 死亡相机
|
|
/// </summary>
|
|
public CinemachineVirtualCamera dieCamear;
|
|
|
|
/// <summary>
|
|
/// 倒计时相机3
|
|
/// </summary>
|
|
public CinemachineVirtualCamera countDown_3;
|
|
|
|
/// <summary>
|
|
/// 倒计时相机2
|
|
/// </summary>
|
|
public CinemachineVirtualCamera countDown_2;
|
|
|
|
/// <summary>
|
|
/// 倒计时相机1
|
|
/// </summary>
|
|
public CinemachineVirtualCamera countDown_1;
|
|
|
|
/// <summary>
|
|
/// 相机大脑
|
|
/// </summary>
|
|
private CinemachineBrain cinemachineBrain;
|
|
|
|
/// <summary>
|
|
/// 相机效果
|
|
/// </summary>
|
|
private CinemachineBasicMultiChannelPerlin noise;
|
|
|
|
/// <summary>
|
|
/// 得到相机
|
|
/// </summary>
|
|
private void GetCamear()
|
|
{
|
|
cinemachineBrain = GameObject.FindAnyObjectByType<CinemachineBrain>();
|
|
noise = gameCamear.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
private void CamearInit()
|
|
{
|
|
hallCamear.Priority = 9;
|
|
shopCamear.Priority = 9;
|
|
gameCamear.Priority = 9;
|
|
winCamear.Priority = 9;
|
|
dieCamear.Priority = 9;
|
|
countDown_3.Priority = 9;
|
|
countDown_2.Priority = 9;
|
|
countDown_1.Priority = 9;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转到大厅相机
|
|
/// </summary>
|
|
public void TurnToHallCamear()
|
|
{
|
|
CamearInit();
|
|
cinemachineBrain.m_DefaultBlend.m_Time = 1f;
|
|
hallCamear.Priority = 10;
|
|
SetHallCamear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转到商店相机
|
|
/// </summary>
|
|
public void TurnToShopCamear(E_CarSizeType e_CarSizeType)
|
|
{
|
|
CamearInit();
|
|
cinemachineBrain.m_DefaultBlend.m_Time = 1f;
|
|
shopCamear.Priority = 10;
|
|
SetShopCamear(e_CarSizeType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转到游戏相机
|
|
/// </summary>
|
|
public void TurnToGameCamear()
|
|
{
|
|
CamearInit();
|
|
gameCamear.Priority = 10;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转到胜利相机
|
|
/// </summary>
|
|
public void TurnToWinCamear()
|
|
{
|
|
CamearInit();
|
|
cinemachineBrain.m_DefaultBlend.m_Time = 1f;
|
|
switch (e_carSizeType)
|
|
{
|
|
case E_CarSizeType.Big:
|
|
winCamear.m_Lens.FieldOfView = 95;
|
|
break;
|
|
case E_CarSizeType.little:
|
|
winCamear.m_Lens.FieldOfView = 60;
|
|
break;
|
|
}
|
|
winCamear.Priority = 10;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转到胜利相机
|
|
/// </summary>
|
|
public void TurnToDieCamear()
|
|
{
|
|
CamearInit();
|
|
cinemachineBrain.m_DefaultBlend.m_Time = 3f;
|
|
dieCamear.Priority = 10;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置大厅相机
|
|
/// </summary>
|
|
/// <param name="e_CarSizeType"></param>
|
|
public void SetHallCamear()
|
|
{
|
|
switch (e_carSizeType)
|
|
{
|
|
case E_CarSizeType.Big:
|
|
hallCamear.m_Lens.FieldOfView = 75;
|
|
break;
|
|
case E_CarSizeType.little:
|
|
hallCamear.m_Lens.FieldOfView = 60;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置游戏相机
|
|
/// </summary>
|
|
public void SetGameCamear(bool isSprint)
|
|
{
|
|
float fieldOfView = gameCamear.m_Lens.FieldOfView;
|
|
float value = 0;
|
|
if (isSprint)
|
|
{
|
|
value = 70;
|
|
}
|
|
else
|
|
{
|
|
value = 60;
|
|
}
|
|
DOTween.To(() => fieldOfView, value => fieldOfView = value, value, 1).OnUpdate(() =>
|
|
{
|
|
gameCamear.m_Lens.FieldOfView = fieldOfView;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置商店相机
|
|
/// </summary>
|
|
public void SetShopCamear(E_CarSizeType e_CarSizeType)
|
|
{
|
|
float fieldOfView = shopCamear.m_Lens.FieldOfView;
|
|
shopCamear.DOKill();
|
|
switch (e_CarSizeType)
|
|
{
|
|
case E_CarSizeType.Big:
|
|
DOTween.To(() => fieldOfView, value => fieldOfView = value, 80, 1).OnUpdate(() =>
|
|
{
|
|
shopCamear.m_Lens.FieldOfView = fieldOfView;
|
|
});
|
|
break;
|
|
case E_CarSizeType.little:
|
|
DOTween.To(() => fieldOfView, value => fieldOfView = value, 60, 1).OnUpdate(() =>
|
|
{
|
|
shopCamear.m_Lens.FieldOfView = fieldOfView;
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 准备
|
|
/// </summary>
|
|
public void GetReady(E_CountDownType e_GetReadyType)
|
|
{
|
|
float startFieldOfVie=0;
|
|
float endFieldOfVie=0;
|
|
switch (e_carSizeType)
|
|
{
|
|
case E_CarSizeType.Big:
|
|
startFieldOfVie = 100;
|
|
endFieldOfVie = 110;
|
|
break;
|
|
case E_CarSizeType.little:
|
|
startFieldOfVie = 60;
|
|
endFieldOfVie = 70;
|
|
break;
|
|
}
|
|
CamearInit();
|
|
cinemachineBrain.m_DefaultBlend.m_Time = 0f;
|
|
CinemachineVirtualCamera cinemachineVirtualCamera=null;
|
|
switch (e_GetReadyType)
|
|
{
|
|
case E_CountDownType.Three:
|
|
cinemachineVirtualCamera = countDown_3;
|
|
break;
|
|
case E_CountDownType.Two:
|
|
cinemachineVirtualCamera = countDown_2;
|
|
break;
|
|
case E_CountDownType.One:
|
|
cinemachineVirtualCamera = countDown_1;
|
|
break;
|
|
}
|
|
cinemachineVirtualCamera.Priority = 10;
|
|
DOTween.To(() => startFieldOfVie, value => startFieldOfVie = value, endFieldOfVie, 1.2f).OnUpdate(() =>
|
|
{
|
|
cinemachineVirtualCamera.m_Lens.FieldOfView = startFieldOfVie;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 震动参数
|
|
/// </summary>
|
|
public void SetShakeValue(float shakeTime, float shakePower = 1, float lessSpeed = 1)
|
|
{
|
|
noise.m_AmplitudeGain = shakePower;
|
|
this.shakeTime = shakeTime;
|
|
this.lessSpeed = lessSpeed;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 相机震动
|
|
/// </summary>
|
|
private void CamearShake()
|
|
{
|
|
if (shakeTime > 0)
|
|
{
|
|
shakeTime -= Time.deltaTime * lessSpeed;
|
|
}
|
|
else
|
|
{
|
|
shakeTime = 0;
|
|
}
|
|
noise.m_FrequencyGain = shakeTime;
|
|
}
|
|
}
|