asdf
This commit is contained in:
@@ -44,12 +44,8 @@ namespace Simulator.Data.Transport
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
InitializeNodePoolAsync().ContinueWith(() =>
|
||||
{
|
||||
});
|
||||
InitializePathPoolAsync().ContinueWith(() =>
|
||||
{
|
||||
});
|
||||
InitializePoolAsync<AGVNode>(nodePool, "node").ContinueWith(pool => { nodePool = pool; });
|
||||
InitializePoolAsync<AGVPath>(pathPool, "path").ContinueWith(pool => { pathPool = pool; });
|
||||
}
|
||||
|
||||
public Vector3 GetNodePosition(string name)
|
||||
@@ -81,29 +77,16 @@ namespace Simulator.Data.Transport
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask InitializeNodePoolAsync()
|
||||
private async UniTask<GameObjectPool<T>> InitializePoolAsync<T>(GameObjectPool<T> existingPool, string key) where T : MonoBehaviour
|
||||
{
|
||||
if (nodePool != null) return;
|
||||
|
||||
var prefab = await Resources.LoadAsync<GameObject>(prefabPaths["node"]) as GameObject;
|
||||
if (existingPool != null) return existingPool;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(prefabPaths[key]) as GameObject;
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogError($"Prefab not found at path: {prefabPaths["node"]}");
|
||||
return;
|
||||
Debug.LogError($"Prefab not found at path: {prefabPaths[key]}");
|
||||
return null;
|
||||
}
|
||||
nodePool = new GameObjectPool<AGVNode>(prefab, transform);
|
||||
}
|
||||
private async UniTask InitializePathPoolAsync()
|
||||
{
|
||||
if (pathPool != null) return;
|
||||
|
||||
var prefab = await Resources.LoadAsync<GameObject>(prefabPaths["path"]) as GameObject;
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogError($"Prefab not found at path: {prefabPaths["path"]}");
|
||||
return;
|
||||
}
|
||||
pathPool = new GameObjectPool<AGVPath>(prefab, transform);
|
||||
return new GameObjectPool<T>(prefab, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,12 +39,13 @@ namespace Simulator.Data.Transport
|
||||
|
||||
public void InitializeAllPools()
|
||||
{
|
||||
InitializeAGVPoolAsync().ContinueWith(() =>
|
||||
InitializePoolAsync<AGV>(agvPool, "agv").ContinueWith(pool =>
|
||||
{
|
||||
agvPool = pool;
|
||||
InitializeDataMappers();
|
||||
});
|
||||
InitializeAFLPoolAsync().ContinueWith(() => { });
|
||||
InitializeForkLiftPoolAsync().ContinueWith(() => { });
|
||||
InitializePoolAsync<AGV>(aflPool, "afl").ContinueWith(pool => { aflPool = pool; });
|
||||
InitializePoolAsync<AGV>(forkLiftPool, "forkLift").ContinueWith(pool => { forkLiftPool = pool; });
|
||||
}
|
||||
|
||||
private void InitializeDataMappers()
|
||||
@@ -135,43 +136,16 @@ namespace Simulator.Data.Transport
|
||||
return agvMap.TryGetValue(name, out var agv) ? agv : null;
|
||||
}
|
||||
|
||||
private async UniTask InitializeAGVPoolAsync()
|
||||
private async UniTask<GameObjectPool<T>> InitializePoolAsync<T>(GameObjectPool<T> existingPool, string key) where T : MonoBehaviour
|
||||
{
|
||||
if (agvPool != null) return;
|
||||
|
||||
var prefab = await Resources.LoadAsync<GameObject>(prefabPaths["agv"]) as GameObject;
|
||||
if (existingPool != null) return existingPool;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(prefabPaths[key]) as GameObject;
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogError($"Prefab not found at path: {prefabPaths["agv"]}");
|
||||
return;
|
||||
Debug.LogError($"Prefab not found at path: {prefabPaths[key]}");
|
||||
return null;
|
||||
}
|
||||
agvPool = new GameObjectPool<AGV>(prefab, _parent);
|
||||
}
|
||||
|
||||
private async UniTask InitializeAFLPoolAsync()
|
||||
{
|
||||
if (aflPool != null) return;
|
||||
|
||||
var prefab = await Resources.LoadAsync<GameObject>(prefabPaths["afl"]) as GameObject;
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogError($"Prefab not found at path: {prefabPaths["afl"]}");
|
||||
return;
|
||||
}
|
||||
aflPool = new GameObjectPool<AGV>(prefab, _parent);
|
||||
}
|
||||
|
||||
private async UniTask InitializeForkLiftPoolAsync()
|
||||
{
|
||||
if (forkLiftPool != null) return;
|
||||
|
||||
var prefab = await Resources.LoadAsync<GameObject>(prefabPaths["forkLift"]) as GameObject;
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogError($"Prefab not found at path: {prefabPaths["forkLift"]}");
|
||||
return;
|
||||
}
|
||||
forkLiftPool = new GameObjectPool<AGV>(prefab, _parent);
|
||||
return new GameObjectPool<T>(prefab, _parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,14 +55,14 @@ namespace Simulator.Data
|
||||
|
||||
public void InitializeAllPools()
|
||||
{
|
||||
InitializeSourcePoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Source, CreateDataMapper(ComponentType.Source)));
|
||||
InitializeSinkPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Sink, CreateDataMapper(ComponentType.Sink)));
|
||||
InitializeQueuePoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Queue, null));
|
||||
InitializeRackPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Rack, CreateDataMapper(ComponentType.Rack)));
|
||||
InitializeAsrsPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.ASRS, CreateDataMapper(ComponentType.ASRS)));
|
||||
InitializeRobotArmPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.RobotArm, CreateDataMapper(ComponentType.RobotArm)));
|
||||
InitializeProcessorPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Processor, CreateDataMapper(ComponentType.Processor)));
|
||||
InitializeWorkerPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Worker, CreateDataMapper(ComponentType.Worker)));
|
||||
InitializePoolAsync<SourceComponent>(_sourcePool, "source").ContinueWith(pool => { _sourcePool = pool; _dataMapperDict.Add(ComponentType.Source, CreateDataMapper(ComponentType.Source)); });
|
||||
InitializePoolAsync<SinkComponent>(_sinkPool, "sink").ContinueWith(pool => { _sinkPool = pool; _dataMapperDict.Add(ComponentType.Sink, CreateDataMapper(ComponentType.Sink)); });
|
||||
InitializePoolAsync<QueueComponent>(_queuePool, "queue").ContinueWith(pool => { _queuePool = pool; _dataMapperDict.Add(ComponentType.Queue, null); });
|
||||
InitializePoolAsync<RackComponent>(_rackPool, "rack").ContinueWith(pool => { _rackPool = pool; _dataMapperDict.Add(ComponentType.Rack, CreateDataMapper(ComponentType.Rack)); });
|
||||
InitializePoolAsync<ASRSComponent>(_asrsPool, "asrs").ContinueWith(pool => { _asrsPool = pool; _dataMapperDict.Add(ComponentType.ASRS, CreateDataMapper(ComponentType.ASRS)); });
|
||||
InitializePoolAsync<RobotArmComponent>(_robotArmPool, "robotArm").ContinueWith(pool => { _robotArmPool = pool; _dataMapperDict.Add(ComponentType.RobotArm, CreateDataMapper(ComponentType.RobotArm)); });
|
||||
InitializePoolAsync<ProcessorComponent>(_processorPool, "processor").ContinueWith(pool => { _processorPool = pool; _dataMapperDict.Add(ComponentType.Processor, CreateDataMapper(ComponentType.Processor)); });
|
||||
InitializePoolAsync<WorkerComponent>(_workerPool, "worker").ContinueWith(pool => { _workerPool = pool; _dataMapperDict.Add(ComponentType.Worker, CreateDataMapper(ComponentType.Worker)); });
|
||||
}
|
||||
|
||||
private DataMapper CreateDataMapper(ComponentType type)
|
||||
@@ -113,68 +113,12 @@ namespace Simulator.Data
|
||||
|
||||
#region Pool Initialization
|
||||
|
||||
private async UniTask InitializeSourcePoolAsync()
|
||||
private async UniTask<GameObjectPool<T>> InitializePoolAsync<T>(GameObjectPool<T> existingPool, string key) where T : MonoBehaviour
|
||||
{
|
||||
if (_sourcePool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["source"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["source"]}"); return; }
|
||||
_sourcePool = new GameObjectPool<SourceComponent>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
private async UniTask InitializeSinkPoolAsync()
|
||||
{
|
||||
if (_sinkPool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["sink"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["sink"]}"); return; }
|
||||
_sinkPool = new GameObjectPool<SinkComponent>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
private async UniTask InitializeQueuePoolAsync()
|
||||
{
|
||||
if (_queuePool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["queue"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["queue"]}"); return; }
|
||||
_queuePool = new GameObjectPool<QueueComponent>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
private async UniTask InitializeRackPoolAsync()
|
||||
{
|
||||
if (_rackPool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["rack"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["rack"]}"); return; }
|
||||
_rackPool = new GameObjectPool<RackComponent>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
private async UniTask InitializeAsrsPoolAsync()
|
||||
{
|
||||
if (_asrsPool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["asrs"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["asrs"]}"); return; }
|
||||
_asrsPool = new GameObjectPool<ASRSComponent>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
private async UniTask InitializeRobotArmPoolAsync()
|
||||
{
|
||||
if (_robotArmPool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["robotArm"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["robotArm"]}"); return; }
|
||||
_robotArmPool = new GameObjectPool<RobotArmComponent>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
private async UniTask InitializeProcessorPoolAsync()
|
||||
{
|
||||
if (_processorPool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["processor"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["processor"]}"); return; }
|
||||
_processorPool = new GameObjectPool<ProcessorComponent>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
private async UniTask InitializeWorkerPoolAsync()
|
||||
{
|
||||
if (_workerPool != null) return;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths["worker"]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths["worker"]}"); return; }
|
||||
_workerPool = new GameObjectPool<WorkerComponent>(prefab, _parentTransform);
|
||||
if (existingPool != null) return existingPool;
|
||||
var prefab = await Resources.LoadAsync<GameObject>(_prefabPaths[key]) as GameObject;
|
||||
if (prefab == null) { Debug.LogError($"Prefab not found at path: {_prefabPaths[key]}"); return null; }
|
||||
return new GameObjectPool<T>(prefab, _parentTransform);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user