diff --git a/Assets/Script/Gameplay/Facility/ButtonInteractController.cs b/Assets/Script/Gameplay/Facility/ButtonInteractController.cs index f361524..b53dbaf 100644 --- a/Assets/Script/Gameplay/Facility/ButtonInteractController.cs +++ b/Assets/Script/Gameplay/Facility/ButtonInteractController.cs @@ -9,7 +9,7 @@ namespace Script.Gameplay.Facility public class ButtonInteractController : BaseFacilityController { [SerializeField] private float signalDuration = 1.0f; // 信号持续时间(秒) - private bool IsPressing = true; + private bool isPressing = false; public override string GetInteractPrompt() { @@ -18,21 +18,23 @@ namespace Script.Gameplay.Facility public override void Interact(GameObject interactor) { - if (!IsPressing) return; + if (isPressing) return; StartCoroutine(SendSignalCoroutine()); - Debug.Log("Button pressed"); + //Debug.Log("Button pressed"); } private IEnumerator SendSignalCoroutine() { SendSignal(true, this.gameObject); - IsPressing = false; + isPressing = true; // 按钮压下的动画或效果可以在这里添加 - + transform.localScale = new Vector3(0.3f, 0.3f, 0.1f); + yield return new WaitForSeconds(signalDuration); SendSignal(false, this.gameObject); - IsPressing = true; + isPressing = false; // 按钮弹起的动画或效果可以在这里添加 + transform.localScale = new Vector3(0.3f, 0.3f, 0.15f); } } } \ No newline at end of file diff --git a/Assets/Script/Gameplay/Facility/ConsoleController.cs b/Assets/Script/Gameplay/Facility/ConsoleController.cs index c55b42b..0f3a71b 100644 --- a/Assets/Script/Gameplay/Facility/ConsoleController.cs +++ b/Assets/Script/Gameplay/Facility/ConsoleController.cs @@ -1,17 +1,28 @@ using System.Collections.Generic; using Script.Gameplay.Connect; +using System.Collections; using Script.Gameplay.Interface; using UnityEngine; namespace Script.Gameplay.Facility { + public enum SendSignalMode + { + Toggle, // 切换,true/false交替发送 + //Hold, // 按住, 触发发送true/false, 结束不发送信号 + Pulse // 脉冲, 发送true,持续一段时间后发送false + } + public class ConsoleController : BaseFacilityController { + [SerializeField] private SendSignalMode sendSignalMode = SendSignalMode.Pulse; [SerializeField] private List controlTarget; [SerializeField] private bool IsBeActive = false; + [SerializeField] private float signalDuration = 1.0f; // 信号持续时间(秒) + private bool isPressing = false; private List controlTargetSignalReceiver = new List(); private bool lastSendSignal = false; - + void Awake() { foreach (var target in controlTarget) @@ -22,29 +33,65 @@ namespace Script.Gameplay.Facility } else { - if(target != null) + if (target != null) Debug.Log(target.name + " is not a supported control target"); } } } - + public override void OnSignalReceived(bool active, GameObject sender) { base.OnSignalReceived(active, sender); IsBeActive = active; } - + public override void Interact(GameObject interactor) + { + if(sendSignalMode== SendSignalMode.Toggle) + { + SendToggleSignal(); + } + else if(sendSignalMode== SendSignalMode.Pulse) + { + SendPulseSignal(); + } + } + private void SendToggleSignal() { if (IsBeActive && controlTargetSignalReceiver != null) { var signal = !lastSendSignal; foreach (var receiver in controlTargetSignalReceiver) - { + { receiver.OnSignalReceived(signal, this.gameObject); } + lastSendSignal = signal; } } + + private void SendPulseSignal() + { + if (IsBeActive) + { + if(isPressing) return; + foreach (var receiver in controlTargetSignalReceiver) + { + StartCoroutine(SendSignalCoroutine(receiver)); + } + } + } + + private IEnumerator SendSignalCoroutine(ISignalReceiver receiver) + { + receiver.OnSignalReceived(true, this.gameObject); + isPressing = true; + // 按钮压下的动画或效果可以在这里添加 + + yield return new WaitForSeconds(signalDuration); + receiver.OnSignalReceived(false, this.gameObject); + isPressing = false; + // 按钮弹起的动画或效果可以在这里添加 + } } -} +} \ No newline at end of file diff --git a/Assets/Script/Gameplay/Facility/LeverInteractController.cs b/Assets/Script/Gameplay/Facility/LeverInteractController.cs index 195b8fb..45f4d0a 100644 --- a/Assets/Script/Gameplay/Facility/LeverInteractController.cs +++ b/Assets/Script/Gameplay/Facility/LeverInteractController.cs @@ -20,6 +20,16 @@ namespace Script.Gameplay.Facility isPulled = !isPulled; SendSignal(isPulled, this.gameObject); // 可选:拉杆动画 + if (isPulled) + { + // 旋转拉杆到下拉位置 + transform.rotation = Quaternion.Euler(0f, 0f, 45f); + } + else + { + // 旋转拉杆回到初始位置 + transform.rotation = Quaternion.Euler(0f, 0f, 0f); + } //Debug.Log(isPulled ? "Lever pulled down" : "Lever reset"); }