This commit is contained in:
2026-03-17 10:52:33 +09:00
parent 28cd9b1582
commit 43772daa55
16 changed files with 358 additions and 448 deletions

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Simulator.Data
@@ -6,127 +8,64 @@ namespace Simulator.Data
{
private ProgressPopupView _progressPopupView;
private SourceProperty _sourceProperty;
private SinkProperty _sinkProperty;
private RackProperty _rackProperty;
private QueueProperty _queueProperty;
private ASRSProperty _asrsProperty;
private RobotArmProperty _robotArmProperty;
private ProcessorProperty _processorProperty;
private ConveyorProperty _conveyorProperty;
private NodeProperty _nodeProperty;
private struct BindingEntry
{
public Action<ComponentType, ComponentDataBase> PropertyHandler;
public bool ShowProgress;
}
private readonly Dictionary<ComponentType, BindingEntry> _bindings = new Dictionary<ComponentType, BindingEntry>();
public void Initialize()
{
_progressPopupView = Object.FindAnyObjectByType<ProgressPopupView>(FindObjectsInactive.Include);
_progressPopupView = GameObject.FindAnyObjectByType<ProgressPopupView>(FindObjectsInactive.Include);
_conveyorProperty = GameObject.FindAnyObjectByType<ConveyorProperty>();
_nodeProperty = GameObject.FindAnyObjectByType<NodeProperty>();
_sourceProperty = Object.FindAnyObjectByType<SourceProperty>();
_sinkProperty = Object.FindAnyObjectByType<SinkProperty>();
_rackProperty = Object.FindAnyObjectByType<RackProperty>();
_queueProperty = Object.FindAnyObjectByType<QueueProperty>();
_asrsProperty = Object.FindAnyObjectByType<ASRSProperty>();
_robotArmProperty = Object.FindAnyObjectByType<RobotArmProperty>();
_processorProperty = Object.FindAnyObjectByType<ProcessorProperty>();
_conveyorProperty = Object.FindAnyObjectByType<ConveyorProperty>();
_nodeProperty = Object.FindAnyObjectByType<NodeProperty>();
Register<SourceProperty>(ComponentType.Source, (p, t, d) => p.SetPropertyWindow(t, d), showProgress: true);
Register<SinkProperty>(ComponentType.Sink, (p, t, d) => p.SetPropertyWindow(t, d), showProgress: true);
Register<ProcessorProperty>(ComponentType.Processor, (p, t, d) => p.SetPropertyWindow(t, d), showProgress: true);
Register<RackProperty>(ComponentType.Rack, (p, t, d) => p.SetPropertyWindow(t, d));
Register<QueueProperty>(ComponentType.Queue, (p, t, d) => p.SetPropertyWindow(t, d));
Register<ASRSProperty>(ComponentType.ASRS, (p, t, d) => p.SetPropertyWindow(t, d));
Register<RobotArmProperty>(ComponentType.RobotArm, (p, t, d) => p.SetPropertyWindow(t, d));
}
private void Register<T>(ComponentType type, Action<T, ComponentType, ComponentDataBase> setup, bool showProgress = false) where T : MonoBehaviour
{
var property = GameObject.FindAnyObjectByType<T>();
if (property == null) return;
_bindings[type] = new BindingEntry
{
PropertyHandler = (t, d) => setup(property, t, d),
ShowProgress = showProgress
};
}
public void BindStandardComponent(ComponentBase component)
{
switch (component.componentType)
{
case ComponentType.Source:
if (_sourceProperty != null)
component.onComponentClicked += _sourceProperty.SetPropertyWindow;
if (_progressPopupView != null)
component.onComponentClicked += _progressPopupView.Show;
break;
case ComponentType.Sink:
if (_sinkProperty != null)
component.onComponentClicked += _sinkProperty.SetPropertyWindow;
if (_progressPopupView != null)
component.onComponentClicked += _progressPopupView.Show;
break;
case ComponentType.Processor:
if (_processorProperty != null)
component.onComponentClicked += _processorProperty.SetPropertyWindow;
if (_progressPopupView != null)
component.onComponentClicked += _progressPopupView.Show;
break;
case ComponentType.Rack:
if (_rackProperty != null)
component.onComponentClicked += _rackProperty.SetPropertyWindow;
break;
case ComponentType.Queue:
if (_queueProperty != null)
component.onComponentClicked += _queueProperty.SetPropertyWindow;
break;
case ComponentType.ASRS:
if (_asrsProperty != null)
component.onComponentClicked += _asrsProperty.SetPropertyWindow;
break;
case ComponentType.RobotArm:
if (_robotArmProperty != null)
component.onComponentClicked += _robotArmProperty.SetPropertyWindow;
break;
case ComponentType.Worker:
break;
}
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)
{
switch (component.componentType)
{
case ComponentType.Source:
if (_sourceProperty != null)
component.onComponentClicked -= _sourceProperty.SetPropertyWindow;
if (_progressPopupView != null)
component.onComponentClicked -= _progressPopupView.Show;
break;
case ComponentType.Sink:
if (_sinkProperty != null)
component.onComponentClicked -= _sinkProperty.SetPropertyWindow;
if (_progressPopupView != null)
component.onComponentClicked -= _progressPopupView.Show;
break;
case ComponentType.Processor:
if (_processorProperty != null)
component.onComponentClicked -= _processorProperty.SetPropertyWindow;
if (_progressPopupView != null)
component.onComponentClicked -= _progressPopupView.Show;
break;
case ComponentType.Rack:
if (_rackProperty != null)
component.onComponentClicked -= _rackProperty.SetPropertyWindow;
break;
case ComponentType.Queue:
if (_queueProperty != null)
component.onComponentClicked -= _queueProperty.SetPropertyWindow;
break;
case ComponentType.ASRS:
if (_asrsProperty != null)
component.onComponentClicked -= _asrsProperty.SetPropertyWindow;
break;
case ComponentType.RobotArm:
if (_robotArmProperty != null)
component.onComponentClicked -= _robotArmProperty.SetPropertyWindow;
break;
case ComponentType.Worker:
break;
}
}
if (!_bindings.TryGetValue(component.componentType, out var entry))
return;
public void UnbindConveyor(ConveyorComponent conveyor)
{
if (_conveyorProperty != null)
conveyor.onConveyorClicked -= _conveyorProperty.SetPropertyWindow;
}
component.onComponentClicked -= entry.PropertyHandler;
public void UnbindNode(NodeComponent node)
{
if (_nodeProperty != null)
node.onConveyorClicked -= _nodeProperty.SetPropertyWindow;
if (entry.ShowProgress && _progressPopupView != null)
component.onComponentClicked -= _progressPopupView.Show;
}
public void BindConveyor(ConveyorComponent conveyor)
@@ -135,10 +74,22 @@ namespace Simulator.Data
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;
}
}
}