Files
2025TapTapGameJam/Assets/Script/Gameplay/Connect/ConnectionLineManager.cs

58 lines
2.0 KiB
C#

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;
[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.");
}
}
}
}
}