refactor(Facility): 使用继承让所有机关都拥有了独自的 可交互 可编辑 可连接设定。大面积重构
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Interface;
|
||||
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
// 只负责在场景中绘制连接线,并处理信号传递
|
||||
public class ConnectionLine : MonoBehaviour
|
||||
public class ConnectionLine : MonoBehaviour, ISignalReceiver, ISignalSender
|
||||
{
|
||||
[SerializeField] private MonoBehaviour monoPointA;
|
||||
[SerializeField] private MonoBehaviour monoPointB;
|
||||
@@ -25,7 +26,7 @@ namespace Script.Gameplay.Connect
|
||||
|
||||
public void SetConnectable(IConnectable pointA, IConnectable pointB)
|
||||
{
|
||||
if(pointA == null || pointB == null)
|
||||
if (pointA == null || pointB == null)
|
||||
{
|
||||
Debug.Log("ConnectionLine requires two valid IConnectable points.");
|
||||
return;
|
||||
@@ -41,7 +42,7 @@ namespace Script.Gameplay.Connect
|
||||
pointB.ConnectionLines.Add(this);
|
||||
SetLineRendererPositions();
|
||||
}
|
||||
|
||||
|
||||
private void SetLineRendererPositions()
|
||||
{
|
||||
if (_pointA != null && _pointB != null)
|
||||
@@ -53,26 +54,46 @@ namespace Script.Gameplay.Connect
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void SignalActive(bool active, GameObject sender)
|
||||
{
|
||||
if (_pointA != null && _pointB != null)
|
||||
{
|
||||
if (sender == _pointA.GetGameObject())
|
||||
{
|
||||
_pointB.OnSignalReceived(active, sender);
|
||||
}
|
||||
else if (sender == _pointB.GetGameObject())
|
||||
{
|
||||
_pointA.OnSignalReceived(active, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public void SignalActive(bool active, GameObject sender)
|
||||
// {
|
||||
// if (_pointA != null && _pointB != null)
|
||||
// {
|
||||
// if (sender == _pointA.GetGameObject())
|
||||
// {
|
||||
// _pointB.OnSignalReceived(active, sender);
|
||||
// }
|
||||
// else if (sender == _pointB.GetGameObject())
|
||||
// {
|
||||
// _pointA.OnSignalReceived(active, sender);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_pointA.ConnectionLines.Remove(this);
|
||||
_pointB.ConnectionLines.Remove(this);
|
||||
}
|
||||
|
||||
public void OnSignalReceived(bool active, GameObject sender)
|
||||
{
|
||||
SendSignal(active,this.gameObject);
|
||||
}
|
||||
|
||||
public void SendSignal(bool active,GameObject sender)
|
||||
{
|
||||
var a = _pointA as ISignalReceiver;
|
||||
var b = _pointB as ISignalReceiver;
|
||||
ISignalReceiver senderR = sender.GetComponent<ISignalReceiver>();
|
||||
if (a != senderR)
|
||||
{
|
||||
a.OnSignalReceived(active, this.gameObject);
|
||||
}
|
||||
if (b != senderR)
|
||||
{
|
||||
b.OnSignalReceived(active, this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Script.Gameplay.Interface;
|
||||
using Core;
|
||||
|
||||
namespace Script.Gameplay.Connect
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
public interface IConnectable : ISignalReceiver
|
||||
{
|
||||
public bool IsEnablePlayerConnect { get; set; }
|
||||
void OnGazeEnter(); // 玩家开始注视时触发
|
||||
void OnGazeExit(); // 玩家停止注视时触发
|
||||
Vector3 GetPosition(); // 获取连接点位置
|
||||
GameObject GetGameObject(); // 获取连接点物体
|
||||
string GetConnectableName(); // 获取连接点名称
|
||||
public List<ConnectionLine> ConnectionLines { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e75a5e9f5792435baf0d8e6b9ccc19b1
|
||||
timeCreated: 1760778892
|
||||
@@ -1,8 +0,0 @@
|
||||
using UnityEngine;
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
public interface ISignalReceiver
|
||||
{
|
||||
public void OnSignalReceived(bool active, GameObject sender);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83ece445f7f45404a9691aad6196f2cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
using UnityEngine;
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
public interface ISignalSender
|
||||
{
|
||||
public void SendSignal(bool active);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc3af72006f342c3b8b7526a5b09e6ee
|
||||
timeCreated: 1760958923
|
||||
Reference in New Issue
Block a user