124 lines
3.3 KiB
C#
124 lines
3.3 KiB
C#
using System.Collections.Generic;
|
|
using Script.Gameplay.Connect;
|
|
using Script.Gameplay.Interface;
|
|
using UnityEngine;
|
|
|
|
namespace Script.Gameplay.Facility
|
|
{
|
|
public class BaseFacilityController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable, ISignalSender,
|
|
ISignalReceiver, IGaze
|
|
{
|
|
[SerializeField] protected bool isEnableInteract = true;
|
|
[SerializeField] protected bool isEnableEdit = true;
|
|
[SerializeField] protected bool isEnableConnect = true;
|
|
[SerializeField] protected string componentName;
|
|
[SerializeField] protected int needSignalCount = 1;
|
|
[SerializeField] protected bool isOpenInEditor = true;
|
|
protected int CurrentSignalCount = 0;
|
|
|
|
public virtual bool IsEnableInteract
|
|
{
|
|
get => isEnableInteract;
|
|
set => isEnableInteract = value;
|
|
}
|
|
|
|
public virtual bool IsEnableEdit
|
|
{
|
|
get => isEnableEdit;
|
|
set => isEnableEdit = value;
|
|
}
|
|
|
|
public virtual bool IsOpenInEditor
|
|
{
|
|
get => isOpenInEditor;
|
|
set
|
|
{
|
|
isOpenInEditor = value;
|
|
IsEnableInteract = value;
|
|
IsEnableConnect = value;
|
|
}
|
|
}
|
|
|
|
public virtual bool IsEnableConnect
|
|
{
|
|
get => isEnableConnect;
|
|
set => isEnableConnect = value;
|
|
}
|
|
|
|
public string ComponentName
|
|
{
|
|
get
|
|
{
|
|
// 如果没有自定义名称,则使用组件名称
|
|
return string.IsNullOrEmpty(componentName) ? GetType().Name : componentName;
|
|
}
|
|
set => componentName = value;
|
|
}
|
|
|
|
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
|
|
|
|
public string GetConnectableName()
|
|
{
|
|
return gameObject.name;
|
|
}
|
|
|
|
public GameObject GetGameObject()
|
|
{
|
|
return gameObject;
|
|
}
|
|
|
|
public virtual string GetInteractPrompt()
|
|
{
|
|
return $"Interact with {componentName}";
|
|
}
|
|
|
|
public Vector3 GetPosition()
|
|
{
|
|
return transform.position;
|
|
}
|
|
|
|
public virtual void Interact(GameObject interactor)
|
|
{
|
|
// Implement interaction logic here
|
|
}
|
|
|
|
public virtual void OnGazeEnter(GameObject go)
|
|
{
|
|
// Handle gaze enter
|
|
}
|
|
|
|
public virtual void OnGazeExit(GameObject go)
|
|
{
|
|
// Handle gaze exit
|
|
}
|
|
|
|
public virtual void OnSignalReceived(bool active, GameObject sender)
|
|
{
|
|
if (active)
|
|
{
|
|
CurrentSignalCount++;
|
|
}
|
|
else
|
|
{
|
|
CurrentSignalCount = Mathf.Max(0, CurrentSignalCount - 1);
|
|
}
|
|
|
|
if (CurrentSignalCount < needSignalCount)
|
|
{
|
|
return;
|
|
}
|
|
// Implement signal received logic here
|
|
}
|
|
|
|
public virtual void SendSignal(bool active, GameObject sender)
|
|
{
|
|
if (ConnectionLines != null)
|
|
{
|
|
foreach (var line in ConnectionLines)
|
|
{
|
|
line.OnSignalReceived(active, this.gameObject);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |