Ver.0.3.0.33
This commit is contained in:
@@ -0,0 +1,797 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using DG.Tweening; // 添加DOTween引用
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
public class FixLightSystem : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
// 注册系统
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
|
||||
// 自动获取呼吸灯的SpriteRenderer
|
||||
if (breathingLight != null)
|
||||
{
|
||||
breathingLightSprite = breathingLight.GetComponentInParent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
// 自动获取小灯的SpriteRenderer
|
||||
smallLightSprites.Clear();
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
var spriteRenderer = light.GetComponentInParent<SpriteRenderer>();
|
||||
smallLightSprites.Add(spriteRenderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Header("呼吸灯设置")]
|
||||
[SerializeField] private Light2D breathingLight;
|
||||
private SpriteRenderer breathingLightSprite;
|
||||
[SerializeField] private float normalBreathingSpeed = 1f;
|
||||
[SerializeField] private float warningBreathingSpeed = 2f;
|
||||
[SerializeField] private float emergencyBreathingSpeed = 3f;
|
||||
[SerializeField] private Color normalColor = Color.green;
|
||||
[SerializeField] private Color warningColor = Color.yellow;
|
||||
[SerializeField] private Color emergencyColor = Color.red;
|
||||
[SerializeField] private RobotECGWave ecgWave;
|
||||
|
||||
[Header("小灯设置")]
|
||||
[SerializeField] private List<Light2D> smallLights = new List<Light2D>();
|
||||
private List<SpriteRenderer> smallLightSprites = new List<SpriteRenderer>();
|
||||
[SerializeField] private float smallLightBlinkInterval = 0.5f;
|
||||
[SerializeField] private int currentSmallLightIndex = 0;
|
||||
[SerializeField] private Color smallLightDefaultColor = Color.yellow;
|
||||
[SerializeField] private Color smallLightNormalColor = Color.green;
|
||||
[SerializeField] private Color smallLightErrorColor = Color.red;
|
||||
[SerializeField] private float operationBlinkDuration = 1f;
|
||||
[SerializeField] private float operationBlinkInterval = 0.1f;
|
||||
|
||||
[Header("环境灯设置")]
|
||||
[SerializeField] private Light2D environmentLight;
|
||||
[SerializeField] private bool isEnvironmentLightFlickering = false;
|
||||
[SerializeField] private float normalEnvironmentIntensity = 1f;
|
||||
[SerializeField] private float warningEnvironmentIntensity = 1f;
|
||||
[SerializeField] private float emergencyEnvironmentIntensity = 1f;
|
||||
[SerializeField] private float brokenLightFlickerInterval = 0.1f;
|
||||
[SerializeField] private float brokenLightFlickerDuration = 0.05f;
|
||||
[SerializeField] private float brokenLightPatternInterval = 2f;
|
||||
[SerializeField] private float brokenLightDarkDuration = 0.8f;
|
||||
[SerializeField] private Color normalEnvironmentColor = Color.white;
|
||||
[SerializeField] private Color warningEnvironmentColor = Color.yellow;
|
||||
[SerializeField] private Color emergencyEnvironmentColor = Color.red;
|
||||
|
||||
[Header("音频设置")]
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
|
||||
[Header("面板灯设置")]
|
||||
[SerializeField] private Light2D panelLight;
|
||||
[SerializeField] private float panelLightIntensity = 1f;
|
||||
[SerializeField] private float panelLightBlinkDuration = 0.2f;
|
||||
[SerializeField] private int panelLightBlinkCount = 2;
|
||||
[SerializeField] private Color panelLightColor = Color.white;
|
||||
|
||||
[Header("警报灯设置")]
|
||||
[SerializeField] private Light2D alarmLight;
|
||||
[SerializeField] private float alarmBlinkSpeed = 0.5f;
|
||||
[SerializeField] private Color alarmLightColor = Color.red;
|
||||
private Tween alarmTween; // 用于控制警报灯闪烁的Tween
|
||||
|
||||
[SerializeField] private bool isSystemOn = false; // 系统开关状态
|
||||
|
||||
private LightState currentState = LightState.Normal;
|
||||
private SmallLightState smallLightState = SmallLightState.Default;
|
||||
private SmallLightStatus smallLightStatus = SmallLightStatus.Normal;
|
||||
private Coroutine currentBreathingCoroutine;
|
||||
private Tween breathingTween; // 添加Tween引用
|
||||
private bool isSystemStarting = false;
|
||||
|
||||
public enum LightState
|
||||
{
|
||||
Normal,
|
||||
Warning,
|
||||
Emergency
|
||||
}
|
||||
|
||||
public enum SmallLightState
|
||||
{
|
||||
Default,
|
||||
Operation
|
||||
}
|
||||
|
||||
public enum SmallLightStatus
|
||||
{
|
||||
Normal,
|
||||
Error
|
||||
}
|
||||
|
||||
public RobotECGWave.WaveType GetCurrentWaveType()
|
||||
{
|
||||
return ecgWave?.waveType ?? RobotECGWave.WaveType.RobotECG;
|
||||
}
|
||||
|
||||
public void SetWaveType(RobotECGWave.WaveType waveType)
|
||||
{
|
||||
if (ecgWave != null)
|
||||
{
|
||||
ecgWave.SetWaveType(waveType);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InitializeSystemState();
|
||||
SetEnvironmentLightBroken();
|
||||
SetEnvironmentLightFlickering(isEnvironmentLightFlickering);
|
||||
StartCoroutine(SmallLightsBlinkRoutine());
|
||||
SetSmallLightState(SmallLightState.Default);
|
||||
}
|
||||
|
||||
private void InitializeSystemState()
|
||||
{
|
||||
if (isSystemOn)
|
||||
{
|
||||
// 系统开启时的初始化
|
||||
if (breathingLight != null)
|
||||
{
|
||||
breathingLight.color = normalColor;
|
||||
breathingLight.intensity = 1f;
|
||||
if (breathingLightSprite != null)
|
||||
{
|
||||
breathingLightSprite.color = normalColor;
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化小灯
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
light.color = smallLightDefaultColor;
|
||||
light.intensity = 1f;
|
||||
}
|
||||
}
|
||||
foreach (var sprite in smallLightSprites)
|
||||
{
|
||||
if (sprite != null)
|
||||
{
|
||||
sprite.color = smallLightDefaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化面板灯
|
||||
if (panelLight != null)
|
||||
{
|
||||
panelLight.color = panelLightColor;
|
||||
panelLight.intensity = panelLightIntensity;
|
||||
}
|
||||
|
||||
// 初始化ECG波形
|
||||
if (ecgWave != null)
|
||||
{
|
||||
ecgWave.gameObject.SetActive(true);
|
||||
}
|
||||
environmentLight.intensity = normalEnvironmentIntensity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 系统关闭时的初始化
|
||||
if (breathingLight != null)
|
||||
{
|
||||
breathingLight.intensity = 0f;
|
||||
if (breathingLightSprite != null)
|
||||
{
|
||||
breathingLightSprite.color = new Color(normalColor.r, normalColor.g, normalColor.b, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭所有小灯
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
light.intensity = 0f;
|
||||
}
|
||||
}
|
||||
foreach (var sprite in smallLightSprites)
|
||||
{
|
||||
if (sprite != null)
|
||||
{
|
||||
sprite.color = new Color(0f, 0f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭面板灯
|
||||
if (panelLight != null)
|
||||
{
|
||||
panelLight.intensity = 0f;
|
||||
}
|
||||
|
||||
// 关闭ECG波形
|
||||
if (ecgWave != null)
|
||||
{
|
||||
ecgWave.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// 设置环境灯为0.8强度
|
||||
if (environmentLight != null)
|
||||
{
|
||||
environmentLight.intensity = 0.4f;
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool IsSystemOn()
|
||||
{
|
||||
return isSystemOn;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetLightState(LightState newState)
|
||||
{
|
||||
if (!isSystemOn) return; // 如果系统未开启,不处理状态变化
|
||||
|
||||
if (currentState != newState)
|
||||
{
|
||||
currentState = newState;
|
||||
UpdateLightsState();
|
||||
Debug.Log($"灯光状态已切换为: {newState}");
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLightsState()
|
||||
{
|
||||
Color targetColor;
|
||||
float breathingSpeed;
|
||||
RobotECGWave.WaveType waveType;
|
||||
Color environmentColor;
|
||||
float environmentIntensity;
|
||||
|
||||
switch (currentState)
|
||||
{
|
||||
case LightState.Normal:
|
||||
targetColor = normalColor;
|
||||
breathingSpeed = normalBreathingSpeed;
|
||||
waveType = RobotECGWave.WaveType.RobotECG;
|
||||
environmentColor = normalEnvironmentColor;
|
||||
environmentIntensity = normalEnvironmentIntensity;
|
||||
break;
|
||||
case LightState.Warning:
|
||||
targetColor = warningColor;
|
||||
breathingSpeed = warningBreathingSpeed;
|
||||
waveType = RobotECGWave.WaveType.Warning;
|
||||
environmentColor = warningEnvironmentColor;
|
||||
environmentIntensity = warningEnvironmentIntensity;
|
||||
break;
|
||||
case LightState.Emergency:
|
||||
targetColor = emergencyColor;
|
||||
breathingSpeed = emergencyBreathingSpeed;
|
||||
waveType = RobotECGWave.WaveType.Noise;
|
||||
environmentColor = normalEnvironmentColor; // 紧急状态不改变环境灯
|
||||
environmentIntensity = normalEnvironmentIntensity;
|
||||
break;
|
||||
default:
|
||||
targetColor = normalColor;
|
||||
breathingSpeed = normalBreathingSpeed;
|
||||
waveType = RobotECGWave.WaveType.RobotECG;
|
||||
environmentColor = normalEnvironmentColor;
|
||||
environmentIntensity = normalEnvironmentIntensity;
|
||||
break;
|
||||
}
|
||||
|
||||
// 处理警报灯
|
||||
if (alarmLight != null)
|
||||
{
|
||||
if (currentState == LightState.Emergency)
|
||||
{
|
||||
// 启动警报灯闪烁
|
||||
alarmLight.color = alarmLightColor;
|
||||
alarmTween?.Kill();
|
||||
alarmTween = DOTween.To(
|
||||
() => alarmLight.intensity,
|
||||
x => alarmLight.intensity = x,
|
||||
4f,
|
||||
alarmBlinkSpeed
|
||||
)
|
||||
.SetLoops(-1, LoopType.Yoyo)
|
||||
.SetEase(Ease.InOutSine);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 关闭警报灯
|
||||
alarmTween?.Kill();
|
||||
alarmLight.intensity = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"更新灯光状态: {currentState}, 目标颜色: {targetColor}, 呼吸速度: {breathingSpeed}");
|
||||
|
||||
// 更新呼吸灯
|
||||
if (breathingLight != null)
|
||||
{
|
||||
breathingLight.color = targetColor;
|
||||
if (breathingLightSprite != null)
|
||||
{
|
||||
breathingLightSprite.color = targetColor;
|
||||
}
|
||||
|
||||
// 使用DOTween实现呼吸效果
|
||||
breathingTween?.Kill();
|
||||
breathingTween = DOTween.To(
|
||||
() => breathingLight.intensity,
|
||||
x => breathingLight.intensity = x,
|
||||
1f,
|
||||
1f / breathingSpeed
|
||||
)
|
||||
.SetLoops(-1, LoopType.Yoyo)
|
||||
.SetEase(Ease.InOutSine);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("呼吸灯组件未设置!");
|
||||
}
|
||||
|
||||
// 更新波形
|
||||
if (ecgWave != null)
|
||||
{
|
||||
ecgWave.SetWaveType(waveType);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("ECG波形组件未设置!");
|
||||
}
|
||||
|
||||
// 更新环境灯颜色和强度
|
||||
if (environmentLight != null)
|
||||
{
|
||||
environmentLight.color = environmentColor;
|
||||
if (isSystemOn)
|
||||
{
|
||||
// 如果系统开启,使用当前状态对应的强度
|
||||
environmentLight.intensity = environmentIntensity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果系统关闭,使用0.8强度
|
||||
environmentLight.intensity = 0.4f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSmallLightState(SmallLightState newState)
|
||||
{
|
||||
if (smallLightState != newState)
|
||||
{
|
||||
smallLightState = newState;
|
||||
if (newState == SmallLightState.Default)
|
||||
{
|
||||
smallLightStatus = SmallLightStatus.Normal;
|
||||
}
|
||||
StartCoroutine(HandleSmallLightStateChange());
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSmallLightStatus(SmallLightStatus newStatus)
|
||||
{
|
||||
if (smallLightStatus != newStatus)
|
||||
{
|
||||
smallLightStatus = newStatus;
|
||||
UpdateSmallLightsStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator HandleSmallLightStateChange()
|
||||
{
|
||||
if (smallLightState == SmallLightState.Operation)
|
||||
{
|
||||
// 快速随机闪烁
|
||||
float endTime = Time.time + operationBlinkDuration;
|
||||
while (Time.time < endTime)
|
||||
{
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
light.intensity = Random.value > 0.5f ? 1f : 0f;
|
||||
}
|
||||
}
|
||||
yield return new WaitForSeconds(operationBlinkInterval);
|
||||
}
|
||||
|
||||
// 切换到常亮状态,根据当前LightState设置颜色
|
||||
Color targetColor = currentState switch
|
||||
{
|
||||
LightState.Normal => smallLightNormalColor,
|
||||
LightState.Warning => warningColor,
|
||||
LightState.Emergency => emergencyColor,
|
||||
_ => smallLightNormalColor
|
||||
};
|
||||
|
||||
for (int i = 0; i < smallLights.Count; i++)
|
||||
{
|
||||
if (smallLights[i] != null)
|
||||
{
|
||||
smallLights[i].color = targetColor;
|
||||
smallLights[i].intensity = 1f;
|
||||
if (i < smallLightSprites.Count && smallLightSprites[i] != null)
|
||||
{
|
||||
smallLightSprites[i].color = targetColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 恢复到默认状态(只有第一个灯闪烁)
|
||||
currentSmallLightIndex = 0;
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
light.color = smallLightDefaultColor;
|
||||
light.intensity = 0f;
|
||||
}
|
||||
}
|
||||
if (smallLights.Count > 0 && smallLights[0] != null)
|
||||
{
|
||||
smallLights[0].intensity = 1f;
|
||||
if (smallLightSprites.Count > 0 && smallLightSprites[0] != null)
|
||||
{
|
||||
smallLightSprites[0].color = smallLightDefaultColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSmallLightsStatus()
|
||||
{
|
||||
Color targetColor = smallLightStatus == SmallLightStatus.Normal ? smallLightNormalColor : smallLightErrorColor;
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
light.color = targetColor;
|
||||
light.intensity = 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator SmallLightsBlinkRoutine()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!isSystemOn)
|
||||
{
|
||||
// 系统关闭时,所有小灯都关闭
|
||||
for (int i = 0; i < smallLights.Count; i++)
|
||||
{
|
||||
if (smallLights[i] != null)
|
||||
{
|
||||
smallLights[i].intensity = 0f;
|
||||
if (i < smallLightSprites.Count && smallLightSprites[i] != null)
|
||||
{
|
||||
smallLightSprites[i].color = new Color(0f, 0f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (smallLightState == SmallLightState.Default)
|
||||
{
|
||||
// 关闭所有小灯
|
||||
for (int i = 0; i < smallLights.Count; i++)
|
||||
{
|
||||
if (smallLights[i] != null)
|
||||
{
|
||||
smallLights[i].intensity = 0f;
|
||||
if (i < smallLightSprites.Count && smallLightSprites[i] != null)
|
||||
{
|
||||
smallLightSprites[i].color = new Color(smallLightDefaultColor.r, smallLightDefaultColor.g, smallLightDefaultColor.b, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 只有第一个灯闪烁黄色
|
||||
if (smallLights.Count > 0 && smallLights[0] != null)
|
||||
{
|
||||
smallLights[0].color = smallLightDefaultColor;
|
||||
smallLights[0].intensity = 1f;
|
||||
if (smallLightSprites.Count > 0 && smallLightSprites[0] != null)
|
||||
{
|
||||
smallLightSprites[0].color = smallLightDefaultColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(smallLightBlinkInterval);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEnvironmentLightBroken()
|
||||
{
|
||||
if (environmentLight != null)
|
||||
{
|
||||
environmentLight.color = currentState switch
|
||||
{
|
||||
LightState.Normal => normalEnvironmentColor,
|
||||
LightState.Warning => warningEnvironmentColor,
|
||||
LightState.Emergency => emergencyEnvironmentColor,
|
||||
_ => normalEnvironmentColor
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEnvironmentLightFlickering(bool isFlickering)
|
||||
{
|
||||
if (isEnvironmentLightFlickering != isFlickering)
|
||||
{
|
||||
isEnvironmentLightFlickering = isFlickering;
|
||||
if (isFlickering)
|
||||
{
|
||||
StartCoroutine(EnvironmentLightFlickerRoutine());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAlarmBlinkSpeed(float speed)
|
||||
{
|
||||
if (speed > 0)
|
||||
{
|
||||
alarmBlinkSpeed = speed;
|
||||
// 如果当前正在闪烁,更新闪烁速度
|
||||
if (currentState == LightState.Emergency && alarmLight != null)
|
||||
{
|
||||
alarmTween?.Kill();
|
||||
alarmTween = DOTween.To(
|
||||
() => alarmLight.intensity,
|
||||
x => alarmLight.intensity = x,
|
||||
1f,
|
||||
alarmBlinkSpeed
|
||||
)
|
||||
.SetLoops(-1, LoopType.Yoyo)
|
||||
.SetEase(Ease.InOutSine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StopAlarmLight()
|
||||
{
|
||||
if (alarmLight != null)
|
||||
{
|
||||
alarmTween?.Kill();
|
||||
alarmLight.intensity = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator EnvironmentLightFlickerRoutine()
|
||||
{
|
||||
while (isEnvironmentLightFlickering)
|
||||
{
|
||||
if (environmentLight != null)
|
||||
{
|
||||
// 获取当前状态对应的强度
|
||||
float currentIntensity = currentState switch
|
||||
{
|
||||
LightState.Normal => normalEnvironmentIntensity,
|
||||
LightState.Warning => warningEnvironmentIntensity,
|
||||
LightState.Emergency => emergencyEnvironmentIntensity,
|
||||
_ => normalEnvironmentIntensity
|
||||
};
|
||||
|
||||
// 默认保持亮起
|
||||
environmentLight.intensity = currentIntensity;
|
||||
|
||||
// 等待随机间隔(3-8秒)
|
||||
yield return new WaitForSeconds(Random.Range(3f, 8f));
|
||||
|
||||
// 随机闪烁2-3次
|
||||
int blinkCount = Random.Range(2, 4);
|
||||
for (int i = 0; i < blinkCount; i++)
|
||||
{
|
||||
// 关闭
|
||||
environmentLight.intensity = 0f;
|
||||
yield return new WaitForSeconds(brokenLightFlickerDuration);
|
||||
|
||||
// 打开
|
||||
environmentLight.intensity = currentIntensity;
|
||||
yield return new WaitForSeconds(brokenLightFlickerInterval);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
// 确保灯光在停止闪烁时是亮着的
|
||||
if (environmentLight != null)
|
||||
{
|
||||
float currentIntensity = currentState switch
|
||||
{
|
||||
LightState.Normal => normalEnvironmentIntensity,
|
||||
LightState.Warning => warningEnvironmentIntensity,
|
||||
LightState.Emergency => emergencyEnvironmentIntensity,
|
||||
_ => normalEnvironmentIntensity
|
||||
};
|
||||
environmentLight.intensity = currentIntensity;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// 清理所有Tween
|
||||
breathingTween?.Kill();
|
||||
alarmTween?.Kill();
|
||||
}
|
||||
|
||||
public IEnumerator StartSystem()
|
||||
{
|
||||
if (isSystemStarting) yield break;
|
||||
if (isSystemOn) yield break;
|
||||
isSystemStarting = true;
|
||||
yield return StartCoroutine(SystemStartSequence());
|
||||
isSystemStarting = false;
|
||||
}
|
||||
|
||||
public void SetSystemPower(bool isOn)
|
||||
{
|
||||
isSystemOn = isOn;
|
||||
if (!isOn)
|
||||
{
|
||||
// 关闭所有灯光(除了环境灯)
|
||||
if (breathingLight != null)
|
||||
{
|
||||
breathingLight.intensity = 0f;
|
||||
if (breathingLightSprite != null)
|
||||
{
|
||||
breathingLightSprite.color = new Color(normalColor.r, normalColor.g, normalColor.b, 0f);
|
||||
}
|
||||
}
|
||||
if (panelLight != null)
|
||||
{
|
||||
panelLight.intensity = 0f;
|
||||
}
|
||||
if (ecgWave != null)
|
||||
{
|
||||
ecgWave.gameObject.SetActive(false);
|
||||
}
|
||||
// 关闭所有小灯
|
||||
for (int i = 0; i < smallLights.Count; i++)
|
||||
{
|
||||
if (smallLights[i] != null)
|
||||
{
|
||||
smallLights[i].intensity = 0f;
|
||||
if (i < smallLightSprites.Count && smallLightSprites[i] != null)
|
||||
{
|
||||
smallLightSprites[i].color = new Color(0f, 0f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 系统开启时,从Normal状态开始
|
||||
//currentState = LightState.Normal;
|
||||
UpdateLightsState();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator SystemStartSequence()
|
||||
{
|
||||
// 1. 激活ECG波形
|
||||
if (ecgWave != null)
|
||||
{
|
||||
ecgWave.gameObject.SetActive(true);
|
||||
}
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
ecgWave.gameObject.SetActive(false);
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
ecgWave.gameObject.SetActive(true);
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
// 2. 小灯自检模式
|
||||
yield return StartCoroutine(SmallLightsSelfCheck());
|
||||
|
||||
// 3. 启动呼吸灯
|
||||
if (breathingLight != null)
|
||||
{
|
||||
breathingLight.intensity = 1f;
|
||||
if (breathingLightSprite != null)
|
||||
{
|
||||
breathingLightSprite.color = normalColor;
|
||||
}
|
||||
}
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// 4. 启动面板灯
|
||||
if (panelLight != null)
|
||||
{
|
||||
// 闪烁两次
|
||||
for (int i = 0; i < panelLightBlinkCount; i++)
|
||||
{
|
||||
// 渐亮
|
||||
DOTween.To(() => panelLight.intensity, x => panelLight.intensity = x, panelLightIntensity, panelLightBlinkDuration * 0.5f)
|
||||
.SetEase(Ease.InOutQuad);
|
||||
DOTween.To(() => environmentLight.intensity, x => environmentLight.intensity = x, normalEnvironmentIntensity, panelLightBlinkDuration * 0.5f)
|
||||
.SetEase(Ease.InOutQuad);
|
||||
yield return new WaitForSeconds(panelLightBlinkDuration);
|
||||
|
||||
// 渐暗
|
||||
DOTween.To(() => panelLight.intensity, x => panelLight.intensity = x, 0f, panelLightBlinkDuration * 0.5f)
|
||||
.SetEase(Ease.InOutQuad);
|
||||
DOTween.To(() => environmentLight.intensity, x => environmentLight.intensity = x, 0f, panelLightBlinkDuration * 0.5f)
|
||||
.SetEase(Ease.InOutQuad);
|
||||
yield return new WaitForSeconds(panelLightBlinkDuration);
|
||||
}
|
||||
// 最后渐亮到常亮状态
|
||||
DOTween.To(() => panelLight.intensity, x => panelLight.intensity = x, panelLightIntensity, panelLightBlinkDuration * 0.5f)
|
||||
.SetEase(Ease.InOutQuad);
|
||||
DOTween.To(() => environmentLight.intensity, x => environmentLight.intensity = x, normalEnvironmentIntensity, panelLightBlinkDuration * 0.5f)
|
||||
.SetEase(Ease.InOutQuad);
|
||||
}
|
||||
|
||||
// 5. 设置系统状态为Normal
|
||||
SetSystemPower(true); // 开启系统
|
||||
}
|
||||
|
||||
private IEnumerator SmallLightsSelfCheck()
|
||||
{
|
||||
// 关闭所有小灯
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
light.intensity = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
// 自检两次
|
||||
for (int check = 0; check < 2; check++)
|
||||
{
|
||||
// 从左到右点亮
|
||||
for (int i = 0; i < smallLights.Count; i++)
|
||||
{
|
||||
if (smallLights[i] != null)
|
||||
{
|
||||
smallLights[i].color = smallLightDefaultColor;
|
||||
smallLights[i].intensity = 1f;
|
||||
if (i < smallLightSprites.Count && smallLightSprites[i] != null)
|
||||
{
|
||||
smallLightSprites[i].color = smallLightDefaultColor;
|
||||
}
|
||||
}
|
||||
yield return new WaitForSeconds(0.05f);
|
||||
}
|
||||
|
||||
// 关闭所有灯
|
||||
foreach (var light in smallLights)
|
||||
{
|
||||
if (light != null)
|
||||
{
|
||||
light.intensity = 0f;
|
||||
}
|
||||
}
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
|
||||
// 恢复到默认状态(只有第一个灯闪烁)
|
||||
if (smallLights.Count > 0 && smallLights[0] != null)
|
||||
{
|
||||
smallLights[0].color = smallLightDefaultColor;
|
||||
smallLights[0].intensity = 1f;
|
||||
if (smallLightSprites.Count > 0 && smallLightSprites[0] != null)
|
||||
{
|
||||
smallLightSprites[0].color = smallLightDefaultColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user