refactor(Facility): 使用继承让所有机关都拥有了独自的 可交互 可编辑 可连接设定。大面积重构

This commit is contained in:
2025-10-22 17:34:58 +08:00
parent 3cdd41ea49
commit 3a0b202325
61 changed files with 1516 additions and 889 deletions

View File

@@ -2,6 +2,7 @@ using System.Linq;
using Core;
using UnityEngine;
using Script.Gameplay.Connect;
using Script.Gameplay.Interface;
using Script.Gameplay.Input;
using System;
@@ -9,14 +10,14 @@ namespace Script.Gameplay.Player
{
public class PlayerConnectController : MonoBehaviour
{
private bool isEnableConnecting = false;
public bool IsEnableConnecting
private bool _isEnablePlayerConnecting = false;
public bool IsEnablePlayerConnecting
{
get => isEnableConnecting;
get => _isEnablePlayerConnecting;
set
{
isEnableConnecting = value;
if (isEnableConnecting == false)
_isEnablePlayerConnecting = value;
if (_isEnablePlayerConnecting == false)
{
// 重置当前目标
CurrentTarget = null;
@@ -83,26 +84,16 @@ namespace Script.Gameplay.Player
void DetectConnectable()
{
if (raycaster == null) return;
if(!IsEnableConnecting) return;
if(!IsEnablePlayerConnecting) return;
GameObject lookAtObj = raycaster.CurrentLookAtObject;
IConnectable hitConnectable = lookAtObj != null ? lookAtObj.GetComponent<IConnectable>() : null;
// 注视对象变化时触发进入/离开(使用接口方法)
if (hitConnectable != previousGazedTarget)
{
if (previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit();
}
if (hitConnectable != null)
{
hitConnectable.OnGazeEnter();
}
previousGazedTarget = hitConnectable;
}
// if (hitConnectable != previousGazedTarget)
// {
// previousGazedTarget = hitConnectable;
// }
CurrentTarget = hitConnectable;
}
@@ -110,8 +101,8 @@ namespace Script.Gameplay.Player
public void SetPointA(IConnectable target)
{
if (target == null) return;
if (!IsEnableConnecting) return;
if (!target.IsEnablePlayerConnect) return;
if (!IsEnablePlayerConnecting) return;
if (!target.IsEnableConnect) return;
outTarget = target;
OnSetPointA?.Invoke(outTarget);
}
@@ -119,9 +110,9 @@ namespace Script.Gameplay.Player
public void SetPointB(IConnectable target)
{
if (target == null) return;
if (!IsEnableConnecting) return;
if (!target.IsEnablePlayerConnect) return;
if (!IsEnablePlayerConnecting) return;
if (!target.IsEnableConnect) return;
inputTarget = target;
OnSetPointB?.Invoke(inputTarget);
}
@@ -129,13 +120,13 @@ namespace Script.Gameplay.Player
public void CutConnectLine(IConnectable target)
{
if (target == null) return;
if(!IsEnableConnecting) return;
if(!IsEnablePlayerConnecting) return;
ConnectionLineManager.Instance.CutTargetConnectionLines(target);
}
private void CreateConnection()
{
if(!IsEnableConnecting) return;
if(!IsEnablePlayerConnecting) return;
if (outTarget != null && inputTarget != null && outTarget != inputTarget)
{
//计算距离

View File

@@ -45,31 +45,31 @@ namespace Script.Gameplay.Player
if (raycaster == null) return;
GameObject lookAtObj = raycaster.CurrentLookAtObject;
if(lookAtObj == null) return;
GameObject hitEditable = null;
if (lookAtObj.GetComponent<IEditableComponent>() != null)
if (lookAtObj != null)
{
hitEditable = lookAtObj;
}
// 如果命中对象与之前注视的不一样,触发进入/离开事件
if (hitEditable != previousGazedTarget)
{
if (previousGazedTarget != null)
if (lookAtObj.GetComponent<IEditableComponent>() != null)
{
// previousGazedTarget.OnGazeExit(this);
hitEditable = lookAtObj;
}
if (hitEditable != null)
{
// hitEditable.OnGazeEnter(this);
}
previousGazedTarget = hitEditable;
}
currentTarget = hitEditable;
// // 如果命中对象与之前注视的不一样,触发进入/离开事件
// if (hitEditable != previousGazedTarget)
// {
// if (previousGazedTarget != null)
// {
// // previousGazedTarget.OnGazeExit(this);
// }
//
// if (hitEditable != null)
// {
// // hitEditable.OnGazeEnter(this);
// }
//
// previousGazedTarget = hitEditable;
// }
}
private void EditTarget()

View File

@@ -47,10 +47,9 @@ namespace Script.Gameplay.Player
var input = InputManager.Instance.Input;
input.Player.Interact.performed += ctx =>
{
if (CurrentTarget != null)
{
CurrentTarget.Interact(this.gameObject);
}
if(CurrentTarget == null) return;
if (!CurrentTarget.IsEnableInteract) return;
CurrentTarget.Interact(this.gameObject);
};
ControllerLocator.Instance.Register(this);
@@ -72,17 +71,17 @@ namespace Script.Gameplay.Player
// 如果命中对象与之前注视的不一样,触发进入/离开事件
if (hitInteractable != previousGazedTarget)
{
if (previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit(this.gameObject);
}
if (hitInteractable != null)
{
hitInteractable.OnGazeEnter(this.gameObject);
// 这里可以显示交互提示UI例如 “E - 开门”
//Debug.Log(hitInteractable.GetInteractPrompt());
}
// if (previousGazedTarget != null)
// {
// previousGazedTarget.OnGazeExit(this.gameObject);
// }
//
// if (hitInteractable != null)
// {
// hitInteractable.OnGazeEnter(this.gameObject);
// // 这里可以显示交互提示UI例如 “E - 开门”
// //Debug.Log(hitInteractable.GetInteractPrompt());
// }
previousGazedTarget = hitInteractable;
}
@@ -95,7 +94,7 @@ namespace Script.Gameplay.Player
isEnablePlayerInteraction = isEnabled;
if (!isEnabled && previousGazedTarget != null)
{
previousGazedTarget.OnGazeExit(this.gameObject);
// previousGazedTarget.OnGazeExit(this.gameObject);
previousGazedTarget = null;
CurrentTarget = null;
}

View File

@@ -76,7 +76,7 @@ namespace Script.Gameplay.Player
if (playerConnectController != null)
{
playerConnectController.IsEnableConnecting = false;
playerConnectController.IsEnablePlayerConnecting = false;
}
break;
case WatchMode.Outside:
@@ -92,7 +92,7 @@ namespace Script.Gameplay.Player
if (playerConnectController != null)
{
playerConnectController.IsEnableConnecting = true;
playerConnectController.IsEnablePlayerConnecting = true;
}
break;