2025-10-18 08:55:38 +08:00
|
|
|
using System;
|
2025-10-19 19:38:52 +08:00
|
|
|
using System.Collections.Generic;
|
2025-10-18 08:55:38 +08:00
|
|
|
using Gameplay.Player;
|
|
|
|
using UnityEngine;
|
|
|
|
using Interface;
|
2025-10-19 19:38:52 +08:00
|
|
|
using Script.Gameplay.Connect;
|
2025-10-18 08:55:38 +08:00
|
|
|
|
|
|
|
namespace Script.Gameplay.Facility
|
|
|
|
{
|
2025-10-19 19:38:52 +08:00
|
|
|
public class DoorInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable
|
2025-10-18 08:55:38 +08:00
|
|
|
{
|
2025-10-19 19:38:52 +08:00
|
|
|
#region Interactable
|
|
|
|
|
2025-10-18 17:14:09 +08:00
|
|
|
public bool Interactable = true;
|
2025-10-18 08:55:38 +08:00
|
|
|
private bool isOpened = false;
|
2025-10-19 19:38:52 +08:00
|
|
|
|
2025-10-18 17:14:09 +08:00
|
|
|
public string GetInteractPrompt()
|
|
|
|
{
|
|
|
|
return "按F进行交互";
|
|
|
|
}
|
2025-10-18 11:00:06 +08:00
|
|
|
|
2025-10-18 17:14:09 +08:00
|
|
|
public void Interact(GameObject interactor)
|
2025-10-18 08:55:38 +08:00
|
|
|
{
|
2025-10-18 11:42:25 +08:00
|
|
|
if (!Interactable) return;
|
2025-10-18 08:55:38 +08:00
|
|
|
if (isOpened)
|
|
|
|
{
|
|
|
|
CloseDoor();
|
|
|
|
isOpened = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OpenDoor();
|
|
|
|
isOpened = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-10-18 17:14:09 +08:00
|
|
|
public void OnGazeEnter(GameObject editor)
|
|
|
|
{
|
2025-10-18 17:16:39 +08:00
|
|
|
//
|
2025-10-18 17:14:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnGazeExit(GameObject editor)
|
|
|
|
{
|
2025-10-18 17:16:39 +08:00
|
|
|
//
|
2025-10-18 17:14:09 +08:00
|
|
|
}
|
|
|
|
|
2025-10-18 08:55:38 +08:00
|
|
|
private void OpenDoor()
|
|
|
|
{
|
2025-10-19 19:38:52 +08:00
|
|
|
// 逆时针旋转90度
|
|
|
|
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(0, -90, 0));
|
2025-10-18 08:55:38 +08:00
|
|
|
Debug.Log("Open door");
|
|
|
|
}
|
2025-10-18 11:00:06 +08:00
|
|
|
|
2025-10-18 08:55:38 +08:00
|
|
|
private void CloseDoor()
|
|
|
|
{
|
2025-10-19 19:38:52 +08:00
|
|
|
// 顺时针旋转90度
|
|
|
|
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(0, 90, 0));
|
2025-10-18 08:55:38 +08:00
|
|
|
Debug.Log("Close door");
|
|
|
|
}
|
2025-10-19 19:38:52 +08:00
|
|
|
|
|
|
|
#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
|
2025-10-18 08:55:38 +08:00
|
|
|
}
|
|
|
|
}
|