提交
This commit is contained in:
@@ -9,10 +9,6 @@ using UnityEngine.EventSystems;
|
||||
using AibisDream.FixSystem;
|
||||
using System.Collections;
|
||||
using AibisDream; // 添加 SpriteFlashSystem 的命名空间
|
||||
using AibisDream.Kit; // 添加 AudioManager 的命名空间
|
||||
using FMOD.Studio; // 添加 FMOD.Studio 命名空间
|
||||
using FMODUnity; // 添加 FMODUnity 命名空间
|
||||
using Sequence = DG.Tweening.Sequence; // 明确指定使用 DG.Tweening.Sequence
|
||||
|
||||
public class ShockSystem : MonoBehaviour
|
||||
{
|
||||
@@ -75,11 +71,6 @@ public class ShockSystem : MonoBehaviour
|
||||
[SerializeField] private float abnormalPanelShakeSpeed = 15f; // 异常状态下面板震动速度
|
||||
[SerializeField] private Color abnormalProgressBarColor = Color.red; // 异常状态下进度条颜色
|
||||
|
||||
[Header("Audio Settings")]
|
||||
[SerializeField] private string chargingEventPath = "event:/FollowInput/defib/defib_charging";
|
||||
[SerializeField] private string shockEventPath = "event:/FollowInput/defib/defib_shock";
|
||||
[SerializeField] private float shockSoundDelay = 0.25f; // 电击音效延迟
|
||||
|
||||
private bool isCharging = false;
|
||||
private float currentProgress = 0f;
|
||||
private float currentLeverAngle = 0f; // 当前杆的角度
|
||||
@@ -98,14 +89,6 @@ public class ShockSystem : MonoBehaviour
|
||||
private Tweener abnormalPanelShakeTweener; // 异常状态下面板震动动画
|
||||
private Color normalProgressBarColor; // 正常状态下进度条颜色
|
||||
|
||||
private bool isChargingSoundPlaying = false;
|
||||
|
||||
private float lastAbnormalUpdateTime = 0f;
|
||||
private float abnormalStateDuration = 0f;
|
||||
private float targetAbnormalAngle = 0f;
|
||||
private float currentAbnormalAngle = 0f;
|
||||
private float abnormalAngleVelocity = 0f;
|
||||
|
||||
// 公共访问器
|
||||
public float FlashDuration => flashDuration;
|
||||
public float FlashInterval => flashInterval;
|
||||
@@ -261,7 +244,7 @@ public class ShockSystem : MonoBehaviour
|
||||
yield return moveRight.WaitForCompletion();
|
||||
yield return movePanel.WaitForCompletion();
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator StopShock()
|
||||
{
|
||||
var moveLeft = leftShockDevice.DOLocalMove(leftDeviceOriginalPos, moveDuration);
|
||||
@@ -271,7 +254,6 @@ public class ShockSystem : MonoBehaviour
|
||||
yield return moveLeft.WaitForCompletion();
|
||||
yield return moveRight.WaitForCompletion();
|
||||
yield return movePanel.WaitForCompletion();
|
||||
StopChargingSound();
|
||||
}
|
||||
|
||||
private void ResetProgress()
|
||||
@@ -308,12 +290,6 @@ public class ShockSystem : MonoBehaviour
|
||||
int progressValue = Mathf.FloorToInt(currentProgress);
|
||||
progressBar.CurrentValue = progressValue;
|
||||
|
||||
// 更新充能音效参数
|
||||
if (isChargingSoundPlaying)
|
||||
{
|
||||
AudioManager.Instance.SetSfxParam(chargingEventPath, "defibProgress", currentProgress / progressBar.MaxValue);
|
||||
}
|
||||
|
||||
// 计算震动强度
|
||||
float currentVibrateStrength = Mathf.Lerp(minVibrateStrength, maxVibrateStrength, progressRatio);
|
||||
|
||||
@@ -352,11 +328,8 @@ public class ShockSystem : MonoBehaviour
|
||||
currentProgress = progressBar.MaxValue;
|
||||
progressBar.CurrentValue = Mathf.FloorToInt(currentProgress);
|
||||
|
||||
// 停止充能音效
|
||||
StopChargingSound();
|
||||
|
||||
// 播放电击音效
|
||||
StartCoroutine(PlayShockEffect());
|
||||
// 触发释放效果
|
||||
DialogController.Instance.StartDialogNode(shockEffectNode);
|
||||
|
||||
// 停止充能
|
||||
isCharging = false;
|
||||
@@ -374,34 +347,6 @@ public class ShockSystem : MonoBehaviour
|
||||
if (!isCharging) return;
|
||||
// 重置上次震动时间
|
||||
lastVibrateTime = Time.time;
|
||||
|
||||
// 开始播放充能音效
|
||||
if (!isChargingSoundPlaying)
|
||||
{
|
||||
AudioManager.Instance.PlaySfx(chargingEventPath);
|
||||
isChargingSoundPlaying = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void StopChargingSound()
|
||||
{
|
||||
if (isChargingSoundPlaying)
|
||||
{
|
||||
AudioManager.Instance.StopSfx(chargingEventPath);
|
||||
isChargingSoundPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator PlayShockEffect()
|
||||
{
|
||||
// 播放电击音效
|
||||
AudioManager.Instance.PlaySfx(shockEventPath);
|
||||
|
||||
// 等待指定延迟
|
||||
yield return new WaitForSeconds(shockSoundDelay);
|
||||
|
||||
// 触发释放效果
|
||||
DialogController.Instance.StartDialogNode(shockEffectNode);
|
||||
}
|
||||
|
||||
public IEnumerator PlayFlashEffect()
|
||||
@@ -498,33 +443,11 @@ public class ShockSystem : MonoBehaviour
|
||||
|
||||
private void UpdateAbnormalState()
|
||||
{
|
||||
// 每0.5-2秒更新一次异常状态
|
||||
if (Time.time - lastAbnormalUpdateTime >= abnormalStateDuration)
|
||||
{
|
||||
lastAbnormalUpdateTime = Time.time;
|
||||
abnormalStateDuration = Random.Range(0.5f, 2f);
|
||||
|
||||
// 随机决定是卡住还是抖动
|
||||
if (Random.value < 0.3f) // 30%概率卡住
|
||||
{
|
||||
targetAbnormalAngle = Random.Range(-abnormalLeverShakeAmount * 0.5f, abnormalLeverShakeAmount * 0.5f);
|
||||
}
|
||||
else // 70%概率抖动
|
||||
{
|
||||
targetAbnormalAngle = Mathf.Sin(Time.time * abnormalLeverShakeSpeed) * abnormalLeverShakeAmount * 0.3f;
|
||||
}
|
||||
}
|
||||
|
||||
// 平滑过渡到目标角度
|
||||
// 在异常状态下,拉杆会不受控制地震动
|
||||
if (lever != null)
|
||||
{
|
||||
currentAbnormalAngle = Mathf.SmoothDamp(
|
||||
currentAbnormalAngle,
|
||||
targetAbnormalAngle,
|
||||
ref abnormalAngleVelocity,
|
||||
0.1f
|
||||
);
|
||||
lever.localRotation = Quaternion.Euler(0, 0, currentAbnormalAngle);
|
||||
float randomAngle = Mathf.Sin(Time.time * abnormalLeverShakeSpeed) * abnormalLeverShakeAmount;
|
||||
lever.localRotation = Quaternion.Euler(0, 0, randomAngle);
|
||||
}
|
||||
|
||||
// 更新充能状态
|
||||
|
||||
Reference in New Issue
Block a user