Files
2025TapTapGameJam/Assets/Script/Gameplay/Facility/DoorInteractController.cs

121 lines
2.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using Gameplay.Player;
using UnityEngine;
using Script.Gameplay.Interface;
using Script.Gameplay.Connect;
namespace Script.Gameplay.Facility
{
public class DoorInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable
{
#region Interactable
public bool Interactable = true;
private bool isOpened = false;
public string GetInteractPrompt()
{
return "按F进行交互";
}
public void Interact(GameObject interactor)
{
if (!Interactable) return;
if (isOpened)
{
CloseDoor();
isOpened = false;
}
else
{
OpenDoor();
isOpened = true;
}
}
public void OnGazeEnter(GameObject editor)
{
2025-10-18 17:16:39 +08:00
//
}
public void OnGazeExit(GameObject editor)
{
2025-10-18 17:16:39 +08:00
//
}
private void OpenDoor()
{
// 逆时针旋转90度
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(0, -90, 0));
Debug.Log("Open door");
}
private void CloseDoor()
{
// 顺时针旋转90度
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(0, 90, 0));
Debug.Log("Close door");
}
#endregion
#region EditableComponent
[SerializeField] private bool isActive = true;
public bool IsActive
{
get => isActive;
set
{
isActive = value;
//具体被编辑的逻辑
Interactable = isActive;
}
}
public string ComponentName { get; set; } = "DoorSwitch";
public LockLevel LockLevel => LockLevel.Red;
#endregion
#region Connectable
public void OnGazeEnter()
{
}
public void OnGazeExit()
{
}
public Vector3 GetPosition()
{
return transform.position;
}
public string GetConnectableName()
{
return gameObject.name;
}
public ConnectionLine OutputConnectionLine { get; set; }
public ConnectionLine InputConnectionLine { get; set; }
public bool IsConnectedOutput { get; set; }
public bool IsConnectedInput { get; set; }
public void ReceiveSignal(bool active, GameObject sender)
{
Interact(sender);
}
public void SendSignal(bool active, GameObject sender)
{
OutputConnectionLine.ReceiveSignal(active);
}
#endregion
}
}