using System; using System.Collections.Generic; using UnityEngine; namespace Simulator.Data { public class ComponentUIBinder { private ProgressPopupView _progressPopupView; private ConveyorProperty _conveyorProperty; private NodeProperty _nodeProperty; private struct BindingEntry { public Action PropertyHandler; public bool ShowProgress; } private readonly Dictionary _bindings = new Dictionary(); public void Initialize() { _progressPopupView = GameObject.FindAnyObjectByType(FindObjectsInactive.Include); _conveyorProperty = GameObject.FindAnyObjectByType(); _nodeProperty = GameObject.FindAnyObjectByType(); Register(ComponentType.Source, (p, t, d) => p.SetPropertyWindow(t, d), showProgress: true); Register(ComponentType.Sink, (p, t, d) => p.SetPropertyWindow(t, d), showProgress: true); Register(ComponentType.Processor, (p, t, d) => p.SetPropertyWindow(t, d), showProgress: true); Register(ComponentType.Rack, (p, t, d) => p.SetPropertyWindow(t, d)); Register(ComponentType.Queue, (p, t, d) => p.SetPropertyWindow(t, d)); Register(ComponentType.ASRS, (p, t, d) => p.SetPropertyWindow(t, d)); Register(ComponentType.RobotArm, (p, t, d) => p.SetPropertyWindow(t, d)); } private void Register(ComponentType type, Action setup, bool showProgress = false) where T : MonoBehaviour { var property = GameObject.FindAnyObjectByType(); if (property == null) return; _bindings[type] = new BindingEntry { PropertyHandler = (t, d) => setup(property, t, d), ShowProgress = showProgress }; } public void BindStandardComponent(ComponentBase component) { if (!_bindings.TryGetValue(component.componentType, out var entry)) return; component.onComponentClicked += entry.PropertyHandler; if (entry.ShowProgress && _progressPopupView != null) component.onComponentClicked += _progressPopupView.Show; } public void UnbindStandardComponent(ComponentBase component) { if (!_bindings.TryGetValue(component.componentType, out var entry)) return; component.onComponentClicked -= entry.PropertyHandler; if (entry.ShowProgress && _progressPopupView != null) component.onComponentClicked -= _progressPopupView.Show; } public void BindConveyor(ConveyorComponent conveyor) { if (_conveyorProperty != null) conveyor.onConveyorClicked += _conveyorProperty.SetPropertyWindow; } public void UnbindConveyor(ConveyorComponent conveyor) { if (_conveyorProperty != null) conveyor.onConveyorClicked -= _conveyorProperty.SetPropertyWindow; } public void BindNode(NodeComponent node) { if (_nodeProperty != null) node.onConveyorClicked += _nodeProperty.SetPropertyWindow; } public void UnbindNode(NodeComponent node) { if (_nodeProperty != null) node.onConveyorClicked -= _nodeProperty.SetPropertyWindow; } } }