feat(): 完成控制台的2中发射信号的模式切换, 优化基本按钮和拉杆的表现
This commit is contained in:
@@ -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<MonoBehaviour> controlTarget;
|
||||
[SerializeField] private bool IsBeActive = false;
|
||||
[SerializeField] private float signalDuration = 1.0f; // 信号持续时间(秒)
|
||||
private bool isPressing = false;
|
||||
private List<ISignalReceiver> controlTargetSignalReceiver = new List<ISignalReceiver>();
|
||||
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;
|
||||
// 按钮弹起的动画或效果可以在这里添加
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user