feat(Signal):实现信号传输的单向连续传播
This commit is contained in:
@@ -93,24 +93,23 @@ namespace Script.Gameplay.Connect
|
||||
|
||||
public void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
SendSignal(active, this.gameObject);
|
||||
SendSignal(active, sender);
|
||||
}
|
||||
|
||||
public bool IsEnableSendSignal { get; set; } = true;
|
||||
|
||||
public void SendSignal(bool active, GameObject sender)
|
||||
{
|
||||
var a = _pointA as ISignalReceiver;
|
||||
var b = _pointB as ISignalReceiver;
|
||||
ISignalReceiver senderR = sender.GetComponent<ISignalReceiver>();
|
||||
if (a != senderR)
|
||||
if (_pointA.GetGameObject() != sender)
|
||||
{
|
||||
a.OnSignalReceived(active, this.gameObject);
|
||||
var pointA = _pointA as ISignalReceiver;
|
||||
pointA?.OnSignalReceived(active, this.gameObject);
|
||||
}
|
||||
|
||||
if (b != senderR)
|
||||
if (_pointB.GetGameObject() != sender)
|
||||
{
|
||||
b.OnSignalReceived(active, this.gameObject);
|
||||
var pointB = _pointB as ISignalReceiver;
|
||||
pointB?.OnSignalReceived(active, this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,11 @@ namespace Script.Gameplay.Facility
|
||||
|
||||
public virtual void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
if (isEnableSendSignal)
|
||||
{
|
||||
SendSignal(active, sender);
|
||||
}
|
||||
|
||||
if (active)
|
||||
{
|
||||
CurrentNeedSignalCount++;
|
||||
@@ -130,20 +135,30 @@ namespace Script.Gameplay.Facility
|
||||
set => isEnableSendSignal = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="active">发送true or false</param>
|
||||
/// <param name="sender">让此物体触发发送的来源者</param>
|
||||
public virtual void SendSignal(bool active, GameObject sender)
|
||||
{
|
||||
if(!IsEnableSendSignal) return;
|
||||
if (ConnectionLines != null)
|
||||
{
|
||||
if (ISignalSender.IsSendToSignalSender(sender))
|
||||
{
|
||||
// 防止信号回传给发送者自己
|
||||
BUGManager.Instance.LogStackOverflowBUG(this.transform);
|
||||
return;
|
||||
}
|
||||
// if (ISignalSender.IsSendToSignalSender(this.gameObject))
|
||||
// {
|
||||
// // 防止信号回传给发送者自己
|
||||
// BUGManager.Instance.LogStackOverflowBUG(this.transform);
|
||||
// return;
|
||||
// }
|
||||
|
||||
foreach (var line in ConnectionLines)
|
||||
{
|
||||
// 排除掉为sender的连接线
|
||||
if (line.gameObject == sender)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
line.OnSignalReceived(active, this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,19 +17,13 @@ namespace Script.Gameplay.Facility
|
||||
public override void Interact(GameObject interactor)
|
||||
{
|
||||
if (!IsEnableInteract) return;
|
||||
PullLever();
|
||||
PullLever(this.gameObject);
|
||||
}
|
||||
|
||||
public override void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
base.OnSignalReceived(active, sender);
|
||||
//PullLever();
|
||||
}
|
||||
|
||||
private void PullLever()
|
||||
private void PullLever(GameObject sender = null)
|
||||
{
|
||||
isPulled = !isPulled;
|
||||
SendSignal(isPulled, this.gameObject);
|
||||
SendSignal(isPulled, sender);
|
||||
// 可选:拉杆动画
|
||||
if (isPulled)
|
||||
{
|
||||
@@ -42,6 +36,5 @@ namespace Script.Gameplay.Facility
|
||||
transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,19 +11,27 @@ namespace Script.Gameplay.Facility
|
||||
[SerializeField] private Vector3 plateOffset = Vector3.up * 0.1f;
|
||||
|
||||
private bool lastState = false;
|
||||
private bool hasObject = false;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!isOpenInEditor) return;
|
||||
bool hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity, detectLayer);
|
||||
hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity, detectLayer);
|
||||
if (hasObject != lastState)
|
||||
{
|
||||
SendSignal(hasObject, this.gameObject);
|
||||
lastState = hasObject;
|
||||
if (hasObject)
|
||||
{
|
||||
// 被压下动画
|
||||
}
|
||||
else
|
||||
{
|
||||
// 弹起动画
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user