refactor(Facility): 使用继承让所有机关都拥有了独自的 可交互 可编辑 可连接设定。大面积重构
This commit is contained in:
50
Assets/Script/Gameplay/Facility/ConsoleController.cs
Normal file
50
Assets/Script/Gameplay/Facility/ConsoleController.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user