2025-10-20 11:02:10 +08:00
|
|
|
using System;
|
2025-10-19 19:38:52 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Core;
|
|
|
|
|
|
|
|
namespace Script.Gameplay.Connect
|
|
|
|
{
|
2025-10-20 11:02:10 +08:00
|
|
|
[Serializable]
|
|
|
|
public class PreviousConnection
|
|
|
|
{
|
|
|
|
public int PreConnectionID;
|
|
|
|
public MonoBehaviour source;
|
|
|
|
public MonoBehaviour target;
|
|
|
|
}
|
2025-10-19 19:38:52 +08:00
|
|
|
public class ConnectionLineManager : MonoSingleton<ConnectionLineManager>
|
|
|
|
{
|
|
|
|
[SerializeField] private GameObject linePrefab;
|
2025-10-20 11:02:10 +08:00
|
|
|
[SerializeField]private List<PreviousConnection> preConnectionLines = new List<PreviousConnection>();
|
|
|
|
private List<ConnectionLine> connectionLines = new List<ConnectionLine>();
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
GeneratePreviousConnectionLines(preConnectionLines);
|
|
|
|
}
|
|
|
|
|
2025-10-20 19:40:55 +08:00
|
|
|
public ConnectionLine GenerateConnectionLine(IConnectable a, IConnectable b)
|
2025-10-19 19:38:52 +08:00
|
|
|
{
|
|
|
|
GameObject lineObject = Instantiate(linePrefab, this.transform);
|
|
|
|
ConnectionLine connectionLine = lineObject.GetComponent<ConnectionLine>();
|
|
|
|
if (connectionLine != null)
|
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
connectionLine.SetConnectable(a, b);
|
2025-10-19 19:38:52 +08:00
|
|
|
connectionLines.Add(connectionLine);
|
|
|
|
return connectionLine;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2025-10-20 19:40:55 +08:00
|
|
|
|
|
|
|
public void CutTargetConnectionLines(IConnectable target)
|
|
|
|
{
|
|
|
|
List<ConnectionLine> linesToRemove = new List<ConnectionLine>();
|
|
|
|
foreach (var line in connectionLines)
|
|
|
|
{
|
|
|
|
if (line != null && (line.Equals(target)))
|
|
|
|
{
|
|
|
|
linesToRemove.Add(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (var line in linesToRemove)
|
|
|
|
{
|
|
|
|
connectionLines.Remove(line);
|
|
|
|
Destroy(line.gameObject);
|
|
|
|
}
|
|
|
|
}
|
2025-10-20 11:02:10 +08:00
|
|
|
|
|
|
|
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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-10-19 19:38:52 +08:00
|
|
|
}
|
|
|
|
}
|