feat(Connect): 完成连线基本玩法,
This commit is contained in:
66
Assets/Script/Gameplay/Connect/ConnectionLine.cs
Normal file
66
Assets/Script/Gameplay/Connect/ConnectionLine.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
// 只负责在场景中绘制连接线,并处理信号传递
|
||||
public class ConnectionLine : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private MonoBehaviour monoSource;
|
||||
[SerializeField] private MonoBehaviour monoTarget;
|
||||
private IConnectable _output;
|
||||
private IConnectable _input;
|
||||
|
||||
private LineRenderer line;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_output = monoSource as IConnectable;
|
||||
_input = monoTarget as IConnectable;
|
||||
|
||||
line = GetComponent<LineRenderer>();
|
||||
|
||||
if (_output != null && _input != null)
|
||||
{
|
||||
SetConnectable(_output, _input);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetConnectable(IConnectable output, IConnectable input)
|
||||
{
|
||||
_output = output;
|
||||
_input = input;
|
||||
_output.IsConnectedOutput = true;
|
||||
_input.IsConnectedInput = true;
|
||||
|
||||
line.SetPositions(new Vector3[]
|
||||
{
|
||||
_output.GetPosition(),
|
||||
_input.GetPosition()
|
||||
});
|
||||
}
|
||||
|
||||
public void ReceiveSignal(bool active)
|
||||
{
|
||||
SendSignal(active);
|
||||
}
|
||||
|
||||
private void SendSignal(bool active)
|
||||
{
|
||||
_input.ReceiveSignal(active,this.gameObject);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_output != null)
|
||||
{
|
||||
_output.IsConnectedOutput = false;
|
||||
}
|
||||
|
||||
if (_input != null)
|
||||
{
|
||||
_input.IsConnectedInput = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Script/Gameplay/Connect/ConnectionLine.cs.meta
Normal file
3
Assets/Script/Gameplay/Connect/ConnectionLine.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73c8f3d3a6144dc780b46b6c363b8ca6
|
||||
timeCreated: 1760779021
|
25
Assets/Script/Gameplay/Connect/ConnectionLineManager.cs
Normal file
25
Assets/Script/Gameplay/Connect/ConnectionLineManager.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
public class ConnectionLineManager : MonoSingleton<ConnectionLineManager>
|
||||
{
|
||||
[SerializeField] private GameObject linePrefab;
|
||||
public List<ConnectionLine> connectionLines = new List<ConnectionLine>();
|
||||
|
||||
public ConnectionLine GenerateConnectionLine(IConnectable source, IConnectable target)
|
||||
{
|
||||
GameObject lineObject = Instantiate(linePrefab, this.transform);
|
||||
ConnectionLine connectionLine = lineObject.GetComponent<ConnectionLine>();
|
||||
if (connectionLine != null)
|
||||
{
|
||||
connectionLine.SetConnectable(source, target);
|
||||
connectionLines.Add(connectionLine);
|
||||
return connectionLine;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 943a23c0c32e460bbc9faac4fe2b5a3e
|
||||
timeCreated: 1760837927
|
19
Assets/Script/Gameplay/Connect/IConnectable.cs
Normal file
19
Assets/Script/Gameplay/Connect/IConnectable.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
public interface IConnectable
|
||||
{
|
||||
void OnGazeEnter(); // 玩家开始注视时触发
|
||||
void OnGazeExit(); // 玩家停止注视时触发
|
||||
Vector3 GetPosition(); // 获取连接点位置
|
||||
string GetConnectableName(); // 获取连接点名称
|
||||
public ConnectionLine OutputConnectionLine { get; set; }
|
||||
public ConnectionLine InputConnectionLine { get; set; }
|
||||
bool IsConnectedOutput { get; set; } // 是否作为输出端连接
|
||||
bool IsConnectedInput { get; set; } // 是否作为输入端连接
|
||||
void ReceiveSignal(bool active, GameObject sender); // 接收信号
|
||||
void SendSignal(bool active, GameObject sender); // 发出信号
|
||||
}
|
||||
}
|
3
Assets/Script/Gameplay/Connect/IConnectable.cs.meta
Normal file
3
Assets/Script/Gameplay/Connect/IConnectable.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e75a5e9f5792435baf0d8e6b9ccc19b1
|
||||
timeCreated: 1760778892
|
Reference in New Issue
Block a user