using AibisDream.Utility; using TMPro; using UnityEngine; using DG.Tweening; using Random = UnityEngine.Random; using System.Collections; namespace AibisDream.FixSystem { public class OscilloscopeSystem : MonoBehaviour { #region 组件索引 private BodyModuleSystem _bodyModuleSystem; private TMP_Text _state; // 显示状态的TextMeshPro组件 private TMP_Text _screenText;// 显示消息的TextMeshPro组件 private WaveformLine _waveformLine; private ScanLine _scanLine; private SpriteRenderer _screen; private WaveSlider _waveSlider; private SpriteButton _deepinButton; #endregion #region 状态 public bool isScanning; public bool isPlaying; public bool canScan; #endregion private void Awake() { FixSystemCenter.SystemDic.Register(this); InitComponentRefs(); } private void InitComponentRefs() { _bodyModuleSystem = GetComponentInParent(); _screenText = transform.Find("Screen Text").GetComponent(); _state = transform.Find("Screen State Text").GetComponent(); _waveformLine = transform.Find("Waveform Visualizer").GetComponent(); _scanLine = transform.Find("Scan Line").GetComponent(); _screen = transform.Find("Screen").GetComponent(); _waveSlider = transform.Find("Wave Slider").GetComponent(); _deepinButton = new SpriteButton(transform.Find("Deepin Button").gameObject, false); _waveformLine.SetLineSize(_screen.bounds.size.x, _screen.bounds.size.y); _scanLine.SetScreenSize(_screen.bounds.size.x, _screen.bounds.size.y); //_screenText.text = ""; MessageBoxSetNull(); _deepinButton.OnButtonDown += HandleDeepInButtonClick; _scanLine.ScanErrorEvent += OnScanSuccess; } private void Update() { _deepinButton.CheckButtonClick(); } #region 对外开放 /// /// 屏幕上播放波形 /// /// 波形类型 /// 是否有错误 public void PlayWave(WaveformType waveformType, bool hasError) { _waveSlider.InitSlider(); isPlaying = true; canScan = hasError; _deepinButton.SetActive(canScan); var initialRandomPhase = Mathf.PI * Random.Range(7, 13) * 0.1f; _waveformLine.PlayWave(waveformType, initialRandomPhase, hasError); } /// /// 停止播放波形 /// public void StopWave() { isPlaying = false; canScan = false; isScanning = false; _deepinButton.SetActive(false); _waveSlider.InitSlider(); _waveformLine.StopWave(); _scanLine.CloseScan(); } public void ChangeDeepInButtonState(bool state) { _deepinButton.SetActive(state); } /// /// 调整相位 /// public void AdjustPhaseShift(float phaseShift) { if (isPlaying) { _waveformLine.AdjustPhaseShift(phaseShift); } } /// /// 开始扫描 /// public void StartScan() { if (!canScan) return; float spikeX = _waveformLine.GetSpikeX(); StartCoroutine(_scanLine.ScanForError(spikeX)); } public void HandleDeepInButtonClick() { // if(_bodyModuleSystem.CableSystem.curBodyModule.data.ignoreWaveCheck==true) // { // _bodyModuleSystem.HandleDeepIn(); // } // else // { // StartScan(); // } _bodyModuleSystem.HandleDeepIn(); } /// /// 扫描成功后 /// public void OnScanSuccess() { _bodyModuleSystem.HandleDeepIn(); _ = CommonUtil.Delay(2000, StopWave); } /// /// 显示消息 /// /// 消息 public void ShowScreenMessage(string message, Color textcolor) { _screenText.text = message; _screenText.color=textcolor; } /// /// 清除消息 /// public void ClearScreenMessage() { _screenText.text = ""; _screenText.color=Color.white; } #endregion public void MessageBoxSetError() { _state.text = "错误"; _state.color = Color.red; // 红色 // _screenText.text = message; // _screenText.color = Color.white; // 默认文本颜色 } public void MessageBoxSetWarning() { _state.text = "警告"; _state.color = new Color(1.0f, 0.55f, 0.0f); // 琥珀色 // _screenText.text = message; // _screenText.color = Color.white; // 默认文本颜色 } public void MessageBoxSetNormal() { _state.text = "正常"; _state.color = Color.blue; // 琥珀色 // _screenText.text = message; // _screenText.color = Color.white; // 默认文本颜色 } public void MessageBoxSetChecking() { _state.text = "检查中"; _state.color = Color.white; // 琥珀色 // _screenText.text = string.Empty; // _screenText.color = Color.white; // 默认文本颜色 } public void MessageBoxSetText(string text) { _screenText.color = Color.white; // 默认文本颜色 _screenText.text += text+"
"; } public void MessageBoxSetNull() { _state.text = "未检测到信号"; _state.color = Color.white; // 蓝色 _screenText.text = ""; _screenText.color = Color.white; // 默认文本颜色 } public IEnumerator EnableDeepInButton() { yield return _deepinButton.GetTransform().DOLocalMoveX(0.35f, 0.5f).WaitForCompletion(); _deepinButton.SetActive(true); } public IEnumerator DisableDeepInButton() { yield return _deepinButton.GetTransform().DOLocalMoveX(-0.2f, 0.5f).WaitForCompletion(); _deepinButton.SetActive(false); } } public enum WaveformType { Default, Sine, Square, Triangle, Sawtooth, HotNoise, Composite, Pulse } }