using UnityEngine; /// /// Tracks which SocketPoint on the held ghost is currently "active" (the one used for snapping). /// Scroll wheel cycles through the iterative sockets defined on the ghost's SocketContainer. /// Uses BaseInputProvider.OnChangeAttachPoint instead of legacy Input.GetAxis. /// public class SocketIterator : MonoBehaviour { private static SocketIterator instance; public static SocketIterator getInstance() => instance; private SocketContainer currentActiveContainer; private SocketPoint currentActiveSocket; private BaseInputProvider inputProvider; private void Awake() { if (instance == null) instance = this; else Destroy(gameObject); } private void Start() { inputProvider = InputProviderManager.getInstance()?.getCurrentInputProvider(); if (inputProvider == null) { Debug.LogWarning("SocketIterator: No input provider found."); return; } // direction: +1 = scroll up (next), -1 = scroll down (previous) inputProvider.OnChangeAttachPoint.AddListener(direction => { if (!InputModeManager.Is(InputMode.ObjectDragging)) return; if (currentActiveContainer == null) return; if (direction > 0) currentActiveContainer.CycleToNextSocket(); else if (direction < 0) currentActiveContainer.CycleToPreviousSocket(); currentActiveSocket = currentActiveContainer.GetActiveSocket(); if (currentActiveSocket != null) Debug.Log($"SocketIterator: switched to socket '{currentActiveSocket.name}'"); }); } /// /// Sets the container to iterate over and resets to the first socket. /// Call this when a new ghost is spawned. /// public void SetActiveContainer(SocketContainer container) { currentActiveContainer = container; if (container != null) { container.ResetToFirstSocket(); currentActiveSocket = container.GetActiveSocket(); } } /// Returns the currently active (highlighted) socket on the held ghost. public SocketPoint GetCurrentActiveSocket() => currentActiveSocket; /// /// Clears state and removes the active socket highlight. /// Call this when a ghost is placed or cancelled. /// public void ClearActiveContainer() { if (currentActiveSocket != null) currentActiveSocket.Highlight(HighlightState.Default); currentActiveContainer = null; currentActiveSocket = null; } }