Files
2025TapTapGameJam/Assets/Script/Gameplay/Edit/ConsoleController.cs

110 lines
2.8 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using Script.Gameplay.Connect;
using Script.Gameplay.Interface;
using UnityEngine;
namespace Script.Gameplay.Edit
{
public class ConsoleController : MonoBehaviour, IConnectable, IEditableComponent, IInteractable
{
[SerializeField] private int needSignalCount = 1;
private int currentSignalCount;
[SerializeField] private MonoBehaviour controlTarget;
public ISignalReceiver controlTargetSignalReceiver;
[SerializeField] private bool IsActive;
private bool lastSendSignal = false;
public bool IsComponentActive { get; set; }
private string componentName = "Console";
public string ComponentName
{
get => string.IsNullOrEmpty(componentName) ? gameObject.name : componentName;
set => componentName = value;
}
public LockLevel LockLevel { get; set; }
public bool IsEnablePlayerConnect { get; set; } = true;
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
void Awake()
{
controlTargetSignalReceiver = controlTarget as ISignalReceiver;
if (controlTargetSignalReceiver == null)
{
Debug.LogError("Control target does not implement ISignalReceiver");
}
}
public void OnGazeEnter()
{
// no-op
}
public void OnGazeExit()
{
// no-op
}
public Vector3 GetPosition()
{
return this.gameObject.transform.position;
}
public GameObject GetGameObject()
{
return gameObject;
}
public string GetConnectableName()
{
return gameObject.name;
}
public void OnSignalReceived(bool active, GameObject sender)
{
if (active)
{
currentSignalCount++;
}
else
{
currentSignalCount--;
}
if (currentSignalCount >= needSignalCount)
{
IsActive = true;
}
else
{
IsActive = false;
}
}
public string GetInteractPrompt()
{
return "Interact to Active";
}
public void Interact(GameObject interactor)
{
if (IsActive && controlTargetSignalReceiver != null)
{
var signal = !lastSendSignal;
controlTargetSignalReceiver.OnSignalReceived(signal, this.gameObject);
lastSendSignal = signal;
}
}
public void OnGazeEnter(GameObject editor)
{
// no-op
}
public void OnGazeExit(GameObject editor)
{
// no-op
}
}
}