using System.Collections.Generic; using BlockSpace.Worlds; using UnityEngine; namespace BlockSpace.Nodes { public sealed class NodeWorldDefaultSpawner : MonoBehaviour { [SerializeField] private NodeGraphManager nodeGraphManager; [SerializeField] private float startX; [SerializeField] private float y = 5f; [SerializeField] private float z = 10f; [SerializeField] private float xSpacing = 0.45f; private void Reset() { nodeGraphManager = GetComponent(); } public void EnsureDefaultNodesSpawnedIfEmpty(List nodeRecords, bool broadcast) { if (nodeGraphManager == null) { nodeGraphManager = GetComponent(); } if (nodeGraphManager == null || (nodeRecords != null && nodeRecords.Count > 0) || nodeGraphManager.GetAllNodesSnapshot().Count > 0) { return; } List allDefinitionsSnapshot = nodeGraphManager.GetAllDefinitionsSnapshot(); if (allDefinitionsSnapshot == null || allDefinitionsSnapshot.Count == 0) { return; } allDefinitionsSnapshot.Sort((NodeDefinition a, NodeDefinition b) => string.CompareOrdinal((a != null) ? a.name : string.Empty, (b != null) ? b.name : string.Empty)); float num = startX; for (int num2 = 0; num2 < allDefinitionsSnapshot.Count; num2++) { NodeDefinition nodeDefinition = allDefinitionsSnapshot[num2]; if (!(nodeDefinition == null)) { nodeGraphManager.SpawnNodeSystem(nodeDefinition, new Vector3(num, y, z), Quaternion.identity, broadcast); num += xSpacing; } } } } }