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 { [SerializeField] private GameObject linePrefab; [SerializeField]private List preConnectionLines = new List(); private List connectionLines = new List(); private void Start() { GeneratePreviousConnectionLines(preConnectionLines); } public ConnectionLine GenerateConnectionLine(IConnectable source, IConnectable target) { GameObject lineObject = Instantiate(linePrefab, this.transform); ConnectionLine connectionLine = lineObject.GetComponent(); if (connectionLine != null) { source.OutputConnectionLine = connectionLine; target.InputConnectionLine = connectionLine; connectionLine.SetConnectable(source, target); connectionLines.Add(connectionLine); return connectionLine; } return null; } public void GeneratePreviousConnectionLines(List 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."); } } } } }