feat(Connect): 实现在场景中提前布置连线,游戏开始后自动连接的功能

This commit is contained in:
2025-10-20 11:02:10 +08:00
parent ec905d2a27
commit bb2c5aa436
3 changed files with 144 additions and 4 deletions

View File

@@ -192,6 +192,18 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2a2113dbf189fbd44bca90f4df91f338, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 2a2113dbf189fbd44bca90f4df91f338, type: 3}
--- !u!114 &183959152 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 605469399670797709, guid: b3e24e2df98d14e4ebc08cc68c071afa,
type: 3}
m_PrefabInstance: {fileID: 2088331975902746738}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3bdc5380046d4cacb0dd579877f320eb, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &410087039 --- !u!1 &410087039
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -582,6 +594,86 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3} m_SourcePrefab: {fileID: 100100000, guid: b3e24e2df98d14e4ebc08cc68c071afa, type: 3}
--- !u!1001 &1240498723
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalPosition.x
value: -5
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalPosition.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalPosition.z
value: -5
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 502199709937918930, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2052340463965227198, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
propertyPath: m_Name
value: Button (3)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: ddd89e93db279184daa80d86bd4e770f, type: 3}
--- !u!114 &1240498724 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 4434834246038522293, guid: ddd89e93db279184daa80d86bd4e770f,
type: 3}
m_PrefabInstance: {fileID: 1240498723}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7f5359facd804a0cb94d416c9c54a167, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1274249800 --- !u!1 &1274249800
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1412,6 +1504,21 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: ConnectionManager value: ConnectionManager
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6919868315282518728, guid: e6007da0e1121fd4ab3b932c054f6256,
type: 3}
propertyPath: preConnectionLines.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6919868315282518728, guid: e6007da0e1121fd4ab3b932c054f6256,
type: 3}
propertyPath: preConnectionLines.Array.data[0].source
value:
objectReference: {fileID: 1240498724}
- target: {fileID: 6919868315282518728, guid: e6007da0e1121fd4ab3b932c054f6256,
type: 3}
propertyPath: preConnectionLines.Array.data[0].target
value:
objectReference: {fileID: 183959152}
- target: {fileID: 8209060139561151121, guid: e6007da0e1121fd4ab3b932c054f6256, - target: {fileID: 8209060139561151121, guid: e6007da0e1121fd4ab3b932c054f6256,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
@@ -1487,6 +1594,7 @@ SceneRoots:
- {fileID: 1781028406820323425} - {fileID: 1781028406820323425}
- {fileID: 366996911271636373} - {fileID: 366996911271636373}
- {fileID: 6191742170513974480} - {fileID: 6191742170513974480}
- {fileID: 1240498723}
- {fileID: 473911345} - {fileID: 473911345}
- {fileID: 865274353} - {fileID: 865274353}
- {fileID: 6350903300567888677} - {fileID: 6350903300567888677}

View File

@@ -1,13 +1,27 @@
using System;
using UnityEngine; using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using Core; using Core;
namespace Script.Gameplay.Connect namespace Script.Gameplay.Connect
{ {
[Serializable]
public class PreviousConnection
{
public int PreConnectionID;
public MonoBehaviour source;
public MonoBehaviour target;
}
public class ConnectionLineManager : MonoSingleton<ConnectionLineManager> public class ConnectionLineManager : MonoSingleton<ConnectionLineManager>
{ {
[SerializeField] private GameObject linePrefab; [SerializeField] private GameObject linePrefab;
public List<ConnectionLine> connectionLines = new List<ConnectionLine>(); [SerializeField]private List<PreviousConnection> preConnectionLines = new List<PreviousConnection>();
private List<ConnectionLine> connectionLines = new List<ConnectionLine>();
private void Start()
{
GeneratePreviousConnectionLines(preConnectionLines);
}
public ConnectionLine GenerateConnectionLine(IConnectable source, IConnectable target) public ConnectionLine GenerateConnectionLine(IConnectable source, IConnectable target)
{ {
@@ -15,11 +29,30 @@ namespace Script.Gameplay.Connect
ConnectionLine connectionLine = lineObject.GetComponent<ConnectionLine>(); ConnectionLine connectionLine = lineObject.GetComponent<ConnectionLine>();
if (connectionLine != null) if (connectionLine != null)
{ {
source.OutputConnectionLine = connectionLine;
target.InputConnectionLine = connectionLine;
connectionLine.SetConnectable(source, target); connectionLine.SetConnectable(source, target);
connectionLines.Add(connectionLine); connectionLines.Add(connectionLine);
return connectionLine; return connectionLine;
} }
return null; return null;
} }
public void GeneratePreviousConnectionLines(List<PreviousConnection> previousConnections)
{
foreach (var preConnection in previousConnections)
{
IConnectable source = preConnection.source as IConnectable;
IConnectable target = preConnection.target as IConnectable;
if (source != null && target != null)
{
GenerateConnectionLine(source, target);
}
else
{
Debug.Log(preConnection.PreConnectionID + " connection failed to load.");
}
}
}
} }
} }

View File

@@ -121,8 +121,7 @@ namespace Script.Gameplay.Player
} }
// 创建连接线 // 创建连接线
ConnectionLine connectionLine = ConnectionLineManager.Instance.GenerateConnectionLine(outTarget, inputTarget); ConnectionLine connectionLine = ConnectionLineManager.Instance.GenerateConnectionLine(outTarget, inputTarget);
outTarget.OutputConnectionLine = connectionLine;
inputTarget.InputConnectionLine = connectionLine;
// 重置信号目标 // 重置信号目标
outTarget = null; outTarget = null;
inputTarget = null; inputTarget = null;