refactor():重构编辑系统,不再需要添加额外的脚本作为可编辑的入口了
This commit is contained in:
116
Assets/Script/Gameplay/Edit/DoorInteractController.cs
Normal file
116
Assets/Script/Gameplay/Edit/DoorInteractController.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Script.Gameplay.Player;
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Interface;
|
||||
using Script.Gameplay.Connect;
|
||||
|
||||
namespace Script.Gameplay.Edit
|
||||
{
|
||||
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)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public void OnGazeExit(GameObject editor)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
private bool isActive = true;
|
||||
|
||||
public bool IsEditableActive
|
||||
{
|
||||
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 GameObject GetGameObject()
|
||||
{
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
public string GetConnectableName()
|
||||
{
|
||||
return gameObject.name;
|
||||
}
|
||||
|
||||
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
|
||||
public void SignalActive(bool active, GameObject sender)
|
||||
{
|
||||
Interact(sender);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user