feat(Connect): 实现在场景中提前布置连线,游戏开始后自动连接的功能
This commit is contained in:
@@ -1,25 +1,58 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
|
||||
namespace Script.Gameplay.Connect
|
||||
{
|
||||
[Serializable]
|
||||
public class PreviousConnection
|
||||
{
|
||||
public int PreConnectionID;
|
||||
public MonoBehaviour source;
|
||||
public MonoBehaviour target;
|
||||
}
|
||||
public class ConnectionLineManager : MonoSingleton<ConnectionLineManager>
|
||||
{
|
||||
[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)
|
||||
{
|
||||
GameObject lineObject = Instantiate(linePrefab, this.transform);
|
||||
ConnectionLine connectionLine = lineObject.GetComponent<ConnectionLine>();
|
||||
if (connectionLine != null)
|
||||
{
|
||||
source.OutputConnectionLine = connectionLine;
|
||||
target.InputConnectionLine = connectionLine;
|
||||
connectionLine.SetConnectable(source, target);
|
||||
connectionLines.Add(connectionLine);
|
||||
return connectionLine;
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user