51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using Script.Gameplay.Connect;
|
||
|
|
using Script.Gameplay.Interface;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace Script.Gameplay.Facility
|
||
|
|
{
|
||
|
|
public class ConsoleController : BaseFacilityController
|
||
|
|
{
|
||
|
|
[SerializeField] private List<MonoBehaviour> controlTarget;
|
||
|
|
[SerializeField] private bool IsBeActive = false;
|
||
|
|
private List<ISignalReceiver> controlTargetSignalReceiver = new List<ISignalReceiver>();
|
||
|
|
private bool lastSendSignal = false;
|
||
|
|
|
||
|
|
void Awake()
|
||
|
|
{
|
||
|
|
foreach (var target in controlTarget)
|
||
|
|
{
|
||
|
|
if (target is ISignalReceiver receiver)
|
||
|
|
{
|
||
|
|
controlTargetSignalReceiver.Add(receiver);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
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 (IsBeActive && controlTargetSignalReceiver != null)
|
||
|
|
{
|
||
|
|
var signal = !lastSendSignal;
|
||
|
|
foreach (var receiver in controlTargetSignalReceiver)
|
||
|
|
{
|
||
|
|
receiver.OnSignalReceived(signal, this.gameObject);
|
||
|
|
}
|
||
|
|
lastSendSignal = signal;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|