2021-12-05 00:40:50 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Cinemachine;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 震动管理员,管理相机和手柄的震动,外部调用静态方法
|
|
|
|
/// </summary>
|
|
|
|
public class VibrationManager : MonoBehaviour
|
|
|
|
{
|
2021-12-12 02:08:39 +08:00
|
|
|
|
|
|
|
// //
|
|
|
|
// void Start(){
|
|
|
|
// HorseShake();
|
|
|
|
// }
|
|
|
|
// //
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 在特洛伊boss关吗?
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
public enum PadShakeitem{
|
|
|
|
移动,
|
|
|
|
跳跃,
|
|
|
|
锤子击中,
|
|
|
|
被击中,
|
|
|
|
发射镰刀,
|
|
|
|
挥动锤子,
|
2021-12-14 01:33:24 +08:00
|
|
|
木马移动,
|
|
|
|
反弹炸弹
|
2021-12-12 02:08:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-14 01:33:24 +08:00
|
|
|
public PadShakeitem itemNow;
|
2021-12-12 02:08:39 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 是否处于特洛伊Boss关
|
|
|
|
/// </summary>
|
|
|
|
public bool inHorseStage;
|
|
|
|
|
2021-12-05 00:40:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 震动相机,仅对于一些微小短小震动使用
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dir">震动方向</param>
|
|
|
|
/// <param name="force">震动力度</param>
|
2021-12-12 02:08:39 +08:00
|
|
|
public void ShakeScream(Vector2 dir,float force){
|
|
|
|
GetComponent<CinemachineImpulseSource>().
|
2021-12-05 00:40:50 +08:00
|
|
|
GenerateImpulse(dir * force);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 震动手柄
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="left">左马达力度(低频)</param>
|
|
|
|
/// <param name="right">右马达力度(高频)</param>
|
|
|
|
/// <param name="time">震动时间</param>
|
2021-12-12 02:08:39 +08:00
|
|
|
/// <param name="item">震动原因</param>
|
|
|
|
public IEnumerator ShakePad(float left, float right, float time, PadShakeitem item){
|
2021-12-05 00:40:50 +08:00
|
|
|
if(Gamepad.current != null){
|
2021-12-12 02:08:39 +08:00
|
|
|
itemNow = item;
|
2021-12-05 00:40:50 +08:00
|
|
|
Gamepad.current.SetMotorSpeeds(left,right);
|
2021-12-14 01:33:24 +08:00
|
|
|
//Debug.Log("正在开始"+item+"的震动");
|
2021-12-05 00:40:50 +08:00
|
|
|
yield return new WaitForSeconds(time);
|
2021-12-12 02:08:39 +08:00
|
|
|
//只有震动项目和震动原因相同的时候,才会触发停止震动
|
|
|
|
//用来解决震动的覆盖问题
|
|
|
|
if(itemNow == item){
|
2021-12-14 01:33:24 +08:00
|
|
|
//Debug.Log("正在结束"+item+"的震动");
|
2021-12-12 02:08:39 +08:00
|
|
|
Gamepad.current.SetMotorSpeeds(0,0);
|
|
|
|
if(inHorseStage)HorseShakePad();
|
|
|
|
}
|
2021-12-05 00:40:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-12 02:08:39 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 木马震动,屏幕轻微快速上下震动
|
|
|
|
/// </summary>
|
|
|
|
public void HorseShake(){
|
|
|
|
transform.Find("木马震动源").
|
|
|
|
GetComponent<CinemachineImpulseSource>().
|
|
|
|
GenerateImpulse();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void HorseShakePad(){
|
2021-12-14 01:33:24 +08:00
|
|
|
StartCoroutine(ShakePad(0f,0.1f,20f,PadShakeitem.木马移动));
|
2021-12-12 02:08:39 +08:00
|
|
|
}
|
|
|
|
}
|