feat(): 实现EditComponent的UI基础,引入TextMeshPro,添加了在Inside状态下不能互动物体的逻辑控制

This commit is contained in:
2025-10-18 11:00:06 +08:00
parent 2614dab342
commit b4f229d29e
85 changed files with 13841 additions and 51 deletions

View File

@@ -8,7 +8,21 @@ namespace Script.Gameplay.Facility
public class DoorInteractController : InteractableBaseController, IEditableComponent
{
[SerializeField] private LockLevel lockLevel;
[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;
private bool isOpened = false;
public override void Interact(GameObject interactor)
{
if (isOpened)
@@ -23,19 +37,11 @@ namespace Script.Gameplay.Facility
}
}
public LockLevel LockLevel => lockLevel;
public void SetActive(bool active)
{
// 实现激活或禁用门的逻辑
Interactable = active;
}
private void OpenDoor()
{
Debug.Log("Open door");
}
private void CloseDoor()
{
Debug.Log("Close door");

View File

@@ -9,7 +9,8 @@ namespace Script.Gameplay.Facility
public interface IEditableComponent
{
public bool IsActive { get; set; }
public string ComponentName { get; set; }
public LockLevel LockLevel { get; }
public void SetActive(bool active);
}
}

View File

@@ -4,7 +4,8 @@
"references": [
"GUID:fd0e97c21c15497f9406b8ee23c1f67e",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -182,17 +182,6 @@ namespace Script.Gameplay.Input
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""ab4a9194-7003-42f9-a13b-f6edf0427a6e"",
""path"": ""<Mouse>/leftButton"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Interact"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""943ba523-b024-410e-a250-735a5ffdf786"",

View File

@@ -11,6 +11,7 @@ namespace Gameplay.Player
[SerializeField] private LayerMask interactableLayer;
[SerializeField] private Camera playerCamera;
[SerializeField] private bool isDrawGizmos;
[SerializeField] private bool isEnablePlayerInteraction = true; // 是否启用玩家交互功能
private IInteractable currentTarget; // 被射线命中的当前可交互对象(用于按键交互)
private IInteractable previousGazedTarget; // 上一次注视的对象(用于注视进入/离开事件)
@@ -38,6 +39,7 @@ namespace Gameplay.Player
void DetectInteractable()
{
if (playerCamera == null) return;
if (!isEnablePlayerInteraction) return;
Ray ray = new Ray(playerCamera.transform.position, playerCamera.transform.forward);
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer))
@@ -76,6 +78,17 @@ namespace Gameplay.Player
currentTarget = null;
}
}
public void SetPlayerInteractionEnabled(bool isEnabled)
{
isEnablePlayerInteraction = isEnabled;
if (!isEnabled && previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit(this.gameObject);
previousGazedTarget = null;
currentTarget = null;
}
}
void OnDrawGizmos()
{

View File

@@ -21,6 +21,7 @@ namespace Gameplay.Player
private InputManager inputManager;
private TimePauseManager timePauseManager;
private WatchMode currentMode = WatchMode.Normal;
private PlayerInteractorController playerInteractorController;
public WatchMode CurrentWatchMode
{
@@ -46,6 +47,7 @@ namespace Gameplay.Player
{
inputManager = InputManager.Instance;
timePauseManager = TimePauseManager.Instance;
playerInteractorController = GetComponent<PlayerInteractorController>();
var input = inputManager.Input;
input.Player.SwitchWatchMode.performed += ctx =>
@@ -73,6 +75,11 @@ namespace Gameplay.Player
timePauseManager.SetPaused(false);
}
if (playerInteractorController != null)
{
playerInteractorController.SetPlayerInteractionEnabled(true);
}
break;
case WatchMode.Inside:
SetSeeLines(false);
@@ -84,6 +91,11 @@ namespace Gameplay.Player
timePauseManager.SetPaused(true);
}
if (playerInteractorController != null)
{
playerInteractorController.SetPlayerInteractionEnabled(false);
}
break;
case WatchMode.Outside:
SetSeeLines(true);
@@ -95,6 +107,11 @@ namespace Gameplay.Player
timePauseManager.SetPaused(false);
}
if (playerInteractorController != null)
{
playerInteractorController.SetPlayerInteractionEnabled(true);
}
break;
default:
throw new ArgumentOutOfRangeException();

View File

@@ -1,19 +1,39 @@
using Core;
using TMPro;
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
using Script.Gameplay.Facility;
namespace UI
{
public class EditableComponentViewer : MonoBehaviour
{
public Component component;
public bool IsOpen;
public void SetComponent()
private IEditableComponent _component;
[SerializeField] private TMP_Text componentName;
[SerializeField] private TMP_Text componentState;
[SerializeField] private Button closeButton;
public void SetComponent(IEditableComponent component)
{
_component = component;
if (component != null)
{
IsOpen = !IsOpen;
component.gameObject.SetActive(IsOpen);
closeButton.onClick.AddListener(OnClickButton);
RefreshUI();
}
}
private void OnClickButton()
{
_component.IsActive = !_component.IsActive;
RefreshUI();
}
private void RefreshUI()
{
if (_component != null)
{
componentName.text = _component.ComponentName;
componentState.text = _component.IsActive ? "Active" : "Inactive";
}
}
}

View File

@@ -146,6 +146,7 @@ namespace UI
var viewer = go.GetComponent<EditableComponentViewer>();
if (viewer != null)
{
viewer.SetComponent(components[i]); // 注入此UI需要的组件数据
componentViewers.Add(viewer);
}