38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using Cinemachine;
|
||
|
using Sirenix.OdinInspector;
|
||
|
using UnityEngine.InputSystem;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 震动管理员,管理相机和手柄的震动,外部调用静态方法
|
||
|
/// </summary>
|
||
|
public class VibrationManager : MonoBehaviour
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 震动相机,仅对于一些微小短小震动使用
|
||
|
/// </summary>
|
||
|
/// <param name="dir">震动方向</param>
|
||
|
/// <param name="force">震动力度</param>
|
||
|
public static void ShakeScream(Vector2 dir,float force){
|
||
|
FindObjectOfType<CinemachineImpulseSource>().
|
||
|
GenerateImpulse(dir * force);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 震动手柄
|
||
|
/// </summary>
|
||
|
/// <param name="left">左马达力度(低频)</param>
|
||
|
/// <param name="right">右马达力度(高频)</param>
|
||
|
/// <param name="time">震动时间</param>
|
||
|
public static IEnumerator ShakePad(float left, float right, float time){
|
||
|
if(Gamepad.current != null){
|
||
|
Gamepad.current.SetMotorSpeeds(left,right);
|
||
|
yield return new WaitForSeconds(time);
|
||
|
Gamepad.current.SetMotorSpeeds(0,0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|