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