1
This commit is contained in:
29
Assets/AGVNeedsScanner.cs
Normal file
29
Assets/AGVNeedsScanner.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XED.VirtualFactory
|
||||
{
|
||||
public class AGVNeedsScanner : NeedsScanner
|
||||
{
|
||||
private readonly VirtualFactoryManager vfManager;
|
||||
AGVManager manager;
|
||||
public AGVNeedsScanner(VirtualFactoryManager vfManager, AGVManager agvManager)
|
||||
{
|
||||
this.vfManager = vfManager;
|
||||
manager = agvManager;
|
||||
}
|
||||
|
||||
public override void Scanning()
|
||||
{
|
||||
CheckAGVCount();
|
||||
ScanningComplete();
|
||||
}
|
||||
void CheckAGVCount()
|
||||
{
|
||||
if (manager.agvs.Count < vfManager.maxAGVCount)
|
||||
{
|
||||
needs.Add(FactoryNeeds.GenerateAGV);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/AGVNeedsScanner.cs.meta
Normal file
2
Assets/AGVNeedsScanner.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 467b71fac96c5774c8c7f08ac58f9496
|
||||
19
Assets/NeedsScanner.cs
Normal file
19
Assets/NeedsScanner.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XED.VirtualFactory
|
||||
{
|
||||
public abstract class NeedsScanner
|
||||
{
|
||||
protected List<FactoryNeeds> needs = new();
|
||||
public event Action<NeedsScanner, List<FactoryNeeds>> onScanningComplete;
|
||||
|
||||
public abstract void Scanning();
|
||||
|
||||
protected void ScanningComplete()
|
||||
{
|
||||
onScanningComplete.Invoke(this, needs);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/NeedsScanner.cs.meta
Normal file
2
Assets/NeedsScanner.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9161584bea128bd4682c86acad11beca
|
||||
31
Assets/ResourceNeedsScanner.cs
Normal file
31
Assets/ResourceNeedsScanner.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace XED.VirtualFactory
|
||||
{
|
||||
public class ResourceNeedsScanner : NeedsScanner
|
||||
{
|
||||
private readonly PortMap portMap;
|
||||
|
||||
public ResourceNeedsScanner(PortMap portMap)
|
||||
{
|
||||
this.portMap = portMap;
|
||||
}
|
||||
|
||||
public override void Scanning()
|
||||
{
|
||||
GeneratePortCheck();
|
||||
ScanningComplete();
|
||||
}
|
||||
|
||||
private void GeneratePortCheck()
|
||||
{
|
||||
if(portMap.TryGetEmptyGeneratePorts(out var ports))
|
||||
{
|
||||
for (int i = 0; i < ports.Count; i++)
|
||||
{
|
||||
needs.Add(FactoryNeeds.GenerateLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/ResourceNeedsScanner.cs.meta
Normal file
2
Assets/ResourceNeedsScanner.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dd1a0ad71ecdc645894bbfbdf539446
|
||||
@@ -253,12 +253,12 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 116334308}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_Father: {fileID: 850406314}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &116334310
|
||||
MonoBehaviour:
|
||||
@@ -281,8 +281,6 @@ MonoBehaviour:
|
||||
startNode: {fileID: 1172928290}
|
||||
stackerHasEmptyCell: 0
|
||||
maxAGVCount: 1
|
||||
agvIsLack: 0
|
||||
loadIsLack: 0
|
||||
needs:
|
||||
--- !u!1001 &125296021
|
||||
PrefabInstance:
|
||||
@@ -1221,6 +1219,50 @@ MonoBehaviour:
|
||||
unLoadSocket: {fileID: 0}
|
||||
portType: 0
|
||||
loader: {fileID: 1832015431}
|
||||
--- !u!1 &696006662
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 696006663}
|
||||
- component: {fileID: 696006664}
|
||||
m_Layer: 0
|
||||
m_Name: StackerCraneManager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &696006663
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 696006662}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 850406314}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &696006664
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 696006662}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: ed97dbd476f7a154c86010b3f67bc371, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &736132299
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1252,6 +1294,40 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1554807645}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &850406313
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 850406314}
|
||||
m_Layer: 0
|
||||
m_Name: Managers
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &850406314
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 850406313}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 116334309}
|
||||
- {fileID: 1133980572}
|
||||
- {fileID: 696006663}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &878306402
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1714,12 +1790,12 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1133980571}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_Father: {fileID: 850406314}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1133980573
|
||||
MonoBehaviour:
|
||||
@@ -2943,7 +3019,6 @@ SceneRoots:
|
||||
- {fileID: 544137894}
|
||||
- {fileID: 1858000805}
|
||||
- {fileID: 1193906775}
|
||||
- {fileID: 1133980572}
|
||||
- {fileID: 850406314}
|
||||
- {fileID: 125296021}
|
||||
- {fileID: 109703751}
|
||||
- {fileID: 116334309}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace XED.VirtualFactory
|
||||
{
|
||||
public enum AGVState
|
||||
{
|
||||
Idle,
|
||||
IdleReady,
|
||||
Moving,
|
||||
Charging,
|
||||
Loading,
|
||||
@@ -26,7 +26,8 @@ namespace XED.VirtualFactory
|
||||
MoveEnd,
|
||||
LoadEnd,
|
||||
UnloadReady,
|
||||
UnloadEnd
|
||||
UnloadEnd,
|
||||
Idle
|
||||
}
|
||||
|
||||
public AGVState state;
|
||||
@@ -51,11 +52,13 @@ namespace XED.VirtualFactory
|
||||
Vector3 moveStartPos;
|
||||
Vector3 nextTargetPos;
|
||||
public AGVNode nextNode;
|
||||
internal Action<AGV> onCompleteTask;
|
||||
|
||||
internal bool isBusy => actionQueue.Count > 0;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
updateAction = Idleing;
|
||||
updateAction = IdleReady;
|
||||
lift = GetComponentInChildren<AGVLift>();
|
||||
liftUpPosition = lift.transform.localPosition;
|
||||
liftDownPosition = lift.transform.localPosition;
|
||||
@@ -67,8 +70,11 @@ namespace XED.VirtualFactory
|
||||
Debug.Log($"{name} is State Changed: {state} -> {newState}");
|
||||
switch (newState)
|
||||
{
|
||||
case AGVState.IdleReady:
|
||||
updateAction = IdleReady;
|
||||
break;
|
||||
case AGVState.Idle:
|
||||
updateAction = Idleing;
|
||||
updateAction = Idle;
|
||||
break;
|
||||
case AGVState.MoveReady:
|
||||
updateAction = MoveReady;
|
||||
@@ -125,6 +131,14 @@ namespace XED.VirtualFactory
|
||||
state = newState;
|
||||
}
|
||||
|
||||
private void Idle()
|
||||
{
|
||||
if(actionQueue.Count > 0)
|
||||
{
|
||||
ExecuteNextAction();
|
||||
}
|
||||
}
|
||||
|
||||
private void LiftDownEnd()
|
||||
{
|
||||
ChangeState(AGVState.Unloading);
|
||||
@@ -132,7 +146,7 @@ namespace XED.VirtualFactory
|
||||
|
||||
private void UnloadEnd()
|
||||
{
|
||||
ChangeState(AGVState.Idle);
|
||||
ChangeState(AGVState.IdleReady);
|
||||
}
|
||||
|
||||
private void Unloading()
|
||||
@@ -159,7 +173,7 @@ namespace XED.VirtualFactory
|
||||
}
|
||||
private void LoadEnd()
|
||||
{
|
||||
ChangeState(AGVState.Idle);
|
||||
ChangeState(AGVState.IdleReady);
|
||||
}
|
||||
|
||||
private void LiftUpEnd()
|
||||
@@ -174,7 +188,7 @@ namespace XED.VirtualFactory
|
||||
if (target.isEmpty)
|
||||
{
|
||||
Debug.Log($"{target} is Empty Load!");
|
||||
ChangeState(AGVState.Idle);
|
||||
ChangeState(AGVState.IdleReady);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -231,7 +245,7 @@ namespace XED.VirtualFactory
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
float moveDistance;
|
||||
private void MoveReady()
|
||||
{
|
||||
currentMovePath = (currentAction as AGVMoveAction).path;
|
||||
@@ -241,6 +255,7 @@ namespace XED.VirtualFactory
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
moveStartPos = transform.position;
|
||||
|
||||
moveDistance = Vector3.Distance(moveStartPos, nextTargetPos);
|
||||
if (Quaternion.Angle(transform.rotation, targetRotation) > 1f)
|
||||
{
|
||||
ChangeState(AGVState.RotateReady);
|
||||
@@ -250,7 +265,7 @@ namespace XED.VirtualFactory
|
||||
}
|
||||
private void Moving()
|
||||
{
|
||||
moveProgress += (spec.maxSpeed * Time.deltaTime);
|
||||
moveProgress += (spec.maxSpeed * Time.deltaTime)/moveDistance;
|
||||
transform.position = Vector3.Lerp(moveStartPos, nextTargetPos, moveProgress);
|
||||
|
||||
if (moveProgress>=1f)
|
||||
@@ -272,15 +287,20 @@ namespace XED.VirtualFactory
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeState(AGVState.Idle);
|
||||
ChangeState(AGVState.IdleReady);
|
||||
}
|
||||
}
|
||||
void Idleing()
|
||||
void IdleReady()
|
||||
{
|
||||
if(actionQueue.Count > 0)
|
||||
{
|
||||
ExecuteNextAction();
|
||||
}
|
||||
else
|
||||
{
|
||||
onCompleteTask?.Invoke(this);
|
||||
ChangeState(AGVState.Idle);
|
||||
}
|
||||
}
|
||||
|
||||
public void ForceSet(AGVNode node)
|
||||
|
||||
@@ -5,11 +5,5 @@ namespace XED.VirtualFactory
|
||||
{
|
||||
public class GeneratePort : OutputPort
|
||||
{
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
base.AfterAwake();
|
||||
Debug.Log("GeneratePort AfterAwake");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,13 @@ namespace XED.VirtualFactory
|
||||
public virtual void Load(Product load)
|
||||
{
|
||||
Debug.Log($"{name} is load");
|
||||
|
||||
load.transform.SetParent(loadPivot);
|
||||
load.transform.localPosition= Vector3.zero;
|
||||
currentLoad = load;
|
||||
load.transform.localPosition = Vector3.zero;
|
||||
load.LocationUpdate(this);
|
||||
onLoadEvent?.Invoke();
|
||||
|
||||
currentLoad = load;
|
||||
onLoadEvent?.Invoke();
|
||||
}
|
||||
|
||||
public virtual void Unload(Loader getter)
|
||||
|
||||
@@ -62,5 +62,18 @@ namespace XED.VirtualFactory
|
||||
inputPort = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
internal bool TryGetEmptyGeneratePorts(out List<GeneratePort> ports)
|
||||
{
|
||||
ports = new List<GeneratePort>();
|
||||
foreach (var p in this.ports)
|
||||
{
|
||||
if (p is GeneratePort pt && pt.isEmpty)
|
||||
{
|
||||
ports.Add(pt);
|
||||
}
|
||||
}
|
||||
return ports.Count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 24cfa40753282b845b69548571a1a451, type: 3}
|
||||
m_Name: AGVSpecData
|
||||
m_EditorClassIdentifier:
|
||||
maxSpeed: 2
|
||||
maxSpeed: 10
|
||||
maxCurveSpeed: 2
|
||||
slowSpeed: 5
|
||||
slowCurveSpeed: 3
|
||||
|
||||
@@ -40,11 +40,12 @@ namespace XED.VirtualFactory
|
||||
float bucketEnd;
|
||||
float pillarMoveProgress;
|
||||
float bucketMoveProgress;
|
||||
public Action<StackerCrane> onCompleteTask;
|
||||
internal bool hasEmptyCell => cells.Any(cell => cell.isEmpty);
|
||||
|
||||
public enum StackerCraneState
|
||||
{
|
||||
Idle,
|
||||
IdleReady,
|
||||
TaskReady,
|
||||
MoveReady,
|
||||
Move,
|
||||
@@ -60,6 +61,7 @@ namespace XED.VirtualFactory
|
||||
LoadEnd,
|
||||
Unload,
|
||||
UnloadEnd,
|
||||
Idle,
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -67,24 +69,18 @@ namespace XED.VirtualFactory
|
||||
updateAction.Invoke();
|
||||
}
|
||||
|
||||
public Action<StackerCrane> onInputLoadEvent;
|
||||
internal Action<StackerCrane> onLoadForkEvent;
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
ChangeState(StackerCraneState.Idle);
|
||||
ChangeState(StackerCraneState.IdleReady);
|
||||
cells = Storage.GetComponentsInChildren<Loader>().ToList();
|
||||
inputPort.onLoadEvent += OnLoadInputPort;
|
||||
}
|
||||
|
||||
private void OnLoadInputPort()
|
||||
{
|
||||
Debug.Log($"On Load Stacker InputPort");
|
||||
if (autoInput)
|
||||
{
|
||||
AddTask(new InputTask());
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTask(StackerCraneTask task)
|
||||
{
|
||||
Debug.Log($"{name} on Add Task");
|
||||
taskQueue.Enqueue(task);
|
||||
}
|
||||
|
||||
@@ -92,6 +88,9 @@ namespace XED.VirtualFactory
|
||||
{
|
||||
switch (newState)
|
||||
{
|
||||
case StackerCraneState.IdleReady:
|
||||
updateAction = IdleReady;
|
||||
break;
|
||||
case StackerCraneState.Idle:
|
||||
updateAction = Idle;
|
||||
break;
|
||||
@@ -143,6 +142,14 @@ namespace XED.VirtualFactory
|
||||
}
|
||||
}
|
||||
|
||||
private void Idle()
|
||||
{
|
||||
if (taskQueue.Count > 0)
|
||||
{
|
||||
ChangeState(StackerCraneState.TaskReady);
|
||||
}
|
||||
}
|
||||
|
||||
private void UnloadEnd()
|
||||
{
|
||||
ChangeState(StackerCraneState.ForkOut);
|
||||
@@ -157,6 +164,7 @@ namespace XED.VirtualFactory
|
||||
private void LoadEnd()
|
||||
{
|
||||
forkProgress = 0f;
|
||||
onLoadForkEvent?.Invoke(this);
|
||||
ChangeState(StackerCraneState.ForkOut);
|
||||
}
|
||||
|
||||
@@ -219,7 +227,7 @@ namespace XED.VirtualFactory
|
||||
{
|
||||
if (actionQueue.Count == 0)
|
||||
{
|
||||
ChangeState(StackerCraneState.Idle);
|
||||
ChangeState(StackerCraneState.IdleReady);
|
||||
return;
|
||||
}
|
||||
currentAction = actionQueue.Dequeue();
|
||||
@@ -234,11 +242,11 @@ namespace XED.VirtualFactory
|
||||
ChangeState(StackerCraneState.MoveReady);
|
||||
break;
|
||||
case StackerCraneMoveToEmptyCellAction moveToEmptyCellAction:
|
||||
moveTarget = cells.FirstOrDefault(cell => cell.isEmpty);
|
||||
moveTarget = cells.First(cell => cell.isEmpty);
|
||||
ChangeState(StackerCraneState.MoveReady);
|
||||
break;
|
||||
case StackerCraneMoveToFullCellAction moveToFullCellAction:
|
||||
moveTarget = cells.FirstOrDefault(cell => !cell.isEmpty);
|
||||
moveTarget = cells.Last(cell => !cell.isEmpty);
|
||||
ChangeState(StackerCraneState.MoveReady);
|
||||
break;
|
||||
case StackerCraneLoadAction loadAction:
|
||||
@@ -294,12 +302,17 @@ namespace XED.VirtualFactory
|
||||
ChangeState(StackerCraneState.ActionReady);
|
||||
}
|
||||
|
||||
private void Idle()
|
||||
private void IdleReady()
|
||||
{
|
||||
if(taskQueue.Count > 0)
|
||||
{
|
||||
ChangeState(StackerCraneState.TaskReady);
|
||||
}
|
||||
else
|
||||
{
|
||||
onCompleteTask?.Invoke(this);
|
||||
ChangeState(StackerCraneState.Idle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -7,26 +8,51 @@ namespace XED.VirtualFactory
|
||||
{
|
||||
public class StackerCraneManager : MonoBehaviour, ISingle
|
||||
{
|
||||
private HashSet<StackerCrane> stackerCranes = new HashSet<StackerCrane>();
|
||||
private StackerCraneLog stackerCraneLog;
|
||||
|
||||
public override void AfterAwake()
|
||||
public StackerCrane[] stackerCranes;
|
||||
void Awake()
|
||||
{
|
||||
stackerCraneLog = FindSingle<StackerCraneLog>();
|
||||
stackerCranes = FindObjectsByType<StackerCrane>(FindObjectsSortMode.None);
|
||||
}
|
||||
|
||||
public void InitStackerCrane(StackerCrane stackerCrane)
|
||||
public bool TryGetEmptyInputStackerCranes(out List<StackerCrane> cranes)
|
||||
{
|
||||
bool added = stackerCranes.Add(stackerCrane);
|
||||
cranes = new();
|
||||
|
||||
//if (added)
|
||||
//{
|
||||
// stackerCrane.onTaskReadyCompletedEvent += stackerCraneLog.TaskReadyLog;
|
||||
// stackerCrane.onTaskEndCompletedEvent += stackerCraneLog.TaskEndLogLog;
|
||||
// stackerCrane.onStateChangeEvent += stackerCraneLog.StateChangeLog;
|
||||
// stackerCrane.onAddTaskCompletedEvent += stackerCraneLog.TaskAddLog;
|
||||
//}
|
||||
}
|
||||
foreach (var crane in stackerCranes)
|
||||
{
|
||||
if (crane.inputPort.isEmpty)
|
||||
{
|
||||
cranes.Add(crane);
|
||||
}
|
||||
}
|
||||
|
||||
return cranes.Count > 0;
|
||||
}
|
||||
|
||||
internal bool TryGetStackerbleStackerCranes(out List<StackerCrane> cranes)
|
||||
{
|
||||
cranes = new List<StackerCrane>();
|
||||
foreach(var crane in stackerCranes)
|
||||
{
|
||||
if(!crane.inputPort.isEmpty && crane.hasEmptyCell)
|
||||
{
|
||||
cranes.Add(crane);
|
||||
}
|
||||
}
|
||||
return cranes.Count > 0;
|
||||
}
|
||||
|
||||
internal bool TryGetUnloaderbleStacker(out List<StackerCrane> cranes)
|
||||
{
|
||||
cranes = new();
|
||||
foreach (var crane in stackerCranes)
|
||||
{
|
||||
if (crane.outputPort.isEmpty && !crane.hasEmptyCell)
|
||||
{
|
||||
cranes.Add(crane);
|
||||
}
|
||||
}
|
||||
return cranes.Count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
56
Assets/StackerCraneNeedsScanner.cs
Normal file
56
Assets/StackerCraneNeedsScanner.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XED.VirtualFactory
|
||||
{
|
||||
public class StackerCraneNeedsScanner : NeedsScanner
|
||||
{
|
||||
private readonly VirtualFactoryManager vfManager;
|
||||
private readonly StackerCraneManager stackerCraneManager;
|
||||
|
||||
public StackerCraneNeedsScanner(VirtualFactoryManager vfManager, StackerCraneManager stackerCraneManager)
|
||||
{
|
||||
this.vfManager = vfManager;
|
||||
this.stackerCraneManager = stackerCraneManager;
|
||||
}
|
||||
|
||||
public override void Scanning()
|
||||
{
|
||||
CheckInputLoadNeeds();
|
||||
CheckStackingTaskNeeds();
|
||||
CheckLoadOutTaskNeeds();
|
||||
ScanningComplete();
|
||||
}
|
||||
|
||||
void CheckLoadOutTaskNeeds()
|
||||
{
|
||||
if(stackerCraneManager.TryGetUnloaderbleStacker(out List<StackerCrane> cranes))
|
||||
{
|
||||
for (int i = 0; i < cranes.Count; ++i)
|
||||
{
|
||||
needs.Add(FactoryNeeds.StackerLoadOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckStackingTaskNeeds()
|
||||
{
|
||||
if(stackerCraneManager.TryGetStackerbleStackerCranes(out var cranes))
|
||||
{
|
||||
for(int i =0;i<cranes.Count; ++i)
|
||||
{
|
||||
needs.Add(FactoryNeeds.Stacking);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckInputLoadNeeds()
|
||||
{
|
||||
if(stackerCraneManager.TryGetEmptyInputStackerCranes(out var cranes))
|
||||
{
|
||||
for (int i = 0; i < cranes.Count; ++i)
|
||||
needs.Add(FactoryNeeds.StackerInputLoad);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/StackerCraneNeedsScanner.cs.meta
Normal file
2
Assets/StackerCraneNeedsScanner.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d7a9b8fa70a9fc4bbbf4e4da4c7af2e
|
||||
@@ -1,12 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using XED.VirtualFactory;
|
||||
|
||||
namespace XED
|
||||
{
|
||||
public class VirtualFactoryManager : MonoBehaviour
|
||||
public enum FactoryNeeds
|
||||
{
|
||||
GenerateAGV,
|
||||
StackerInputLoad,
|
||||
Stacking,
|
||||
GenerateLoad,
|
||||
StackerLoadOut,
|
||||
}
|
||||
|
||||
public class VirtualFactoryManager : MonoBehaviour
|
||||
{
|
||||
public List<StackerCrane> stackerCranes = new();
|
||||
public AGVManager agvManager;
|
||||
@@ -18,19 +28,17 @@ namespace XED
|
||||
|
||||
public bool stackerHasEmptyCell;
|
||||
public int maxAGVCount = 4;
|
||||
public enum FactoryNeeds
|
||||
{
|
||||
NeedAGV,
|
||||
NeedLoad,
|
||||
NeedStackerInputLoad,
|
||||
NeedStackerInput,
|
||||
}
|
||||
|
||||
public bool agvIsLack;
|
||||
public bool loadIsLack;
|
||||
|
||||
public List<FactoryNeeds> needs = new();
|
||||
public event Action scanningAction;
|
||||
public event Action solutionAction;
|
||||
|
||||
public AGVNeedsScanner agvNeedScanner;
|
||||
public ResourceNeedsScanner resourceNeedsChecker;
|
||||
public StackerCraneNeedsScanner stackerNeedsChecker;
|
||||
public List<NeedsScanner> scanners = new();
|
||||
|
||||
HashSet<StackerCrane> stackingReadys = new();
|
||||
private StackerCraneManager stackerCraneManager;
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
agvMap = FindSingle<AGVMap>();
|
||||
@@ -38,65 +46,128 @@ namespace XED
|
||||
agvManager = FindSingle<AGVManager>();
|
||||
stackerCranes = FindObjectsByType<StackerCrane>(UnityEngine.FindObjectsSortMode.None).ToList();
|
||||
|
||||
scanningAction += CheckAGVCount;
|
||||
scanningAction += CheckStackerSpace;
|
||||
scanningAction += CheckStackerInput;
|
||||
agvNeedScanner = new AGVNeedsScanner(this, agvManager);
|
||||
resourceNeedsChecker = new ResourceNeedsScanner(portMap);
|
||||
stackerNeedsChecker = new StackerCraneNeedsScanner(this, stackerCraneManager);
|
||||
|
||||
scanners.Add(agvNeedScanner);
|
||||
scanners.Add(resourceNeedsChecker);
|
||||
scanners.Add(stackerNeedsChecker);
|
||||
|
||||
agvNeedScanner.onScanningComplete += OnScanningComplete;
|
||||
resourceNeedsChecker.onScanningComplete += OnScanningComplete;
|
||||
stackerNeedsChecker.onScanningComplete += OnScanningComplete;
|
||||
|
||||
Scanning();
|
||||
}
|
||||
|
||||
private void CheckStackerInput()
|
||||
void Scanning()
|
||||
{
|
||||
Debug.Log("Needs Scanning");
|
||||
foreach (var scanner in scanners)
|
||||
{
|
||||
scanner.Scanning();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnScanningComplete(NeedsScanner scanner, List<FactoryNeeds> list)
|
||||
{
|
||||
Debug.Log($"On Needs Scanning Complete {scanner.GetType().Name}");
|
||||
switch (scanner)
|
||||
{
|
||||
case AGVNeedsScanner _:
|
||||
AGVNeedsSolutioning(list);
|
||||
break;
|
||||
case ResourceNeedsScanner _:
|
||||
ResourceNeedsSolutioning(list);
|
||||
break;
|
||||
case StackerCraneNeedsScanner _:
|
||||
StackerNeedsSolutioning(list);
|
||||
break;
|
||||
}
|
||||
list.Clear();
|
||||
}
|
||||
|
||||
private void StackerNeedsSolutioning(List<FactoryNeeds> list)
|
||||
{
|
||||
foreach (var needs in list)
|
||||
{
|
||||
switch (needs)
|
||||
{
|
||||
case FactoryNeeds.StackerInputLoad:
|
||||
DeliveryStackerInputLoad();
|
||||
break;
|
||||
case FactoryNeeds.Stacking:
|
||||
StackerStacking();
|
||||
break;
|
||||
case FactoryNeeds.StackerLoadOut:
|
||||
StackerLoadOut();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void StackerLoadOut()
|
||||
{
|
||||
foreach (var stacker in stackerCranes)
|
||||
{
|
||||
if (!stacker.hasEmptyCell)
|
||||
continue;
|
||||
|
||||
if (stacker.inputPort.isEmpty)
|
||||
{
|
||||
Debug.Log("Need Stacker Input Load");
|
||||
needs.Add(FactoryNeeds.NeedStackerInputLoad);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"Need Stacker Input");
|
||||
needs.Add(FactoryNeeds.NeedStackerInput);
|
||||
return;
|
||||
stacker.AddTask(new OutputTask());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void ResourceNeedsSolutioning(List<FactoryNeeds> list)
|
||||
{
|
||||
ScanningVirtualFactory();
|
||||
Solutioning();
|
||||
}
|
||||
|
||||
void ScanningVirtualFactory()
|
||||
{
|
||||
scanningAction?.Invoke();
|
||||
}
|
||||
|
||||
void Solutioning()
|
||||
{
|
||||
foreach(var n in needs)
|
||||
foreach (var needs in list)
|
||||
{
|
||||
switch (n)
|
||||
switch (needs)
|
||||
{
|
||||
case FactoryNeeds.NeedAGV:
|
||||
solutionAction += GenerateAGV;
|
||||
break;
|
||||
case FactoryNeeds.NeedLoad:
|
||||
solutionAction += GenerateLoad;
|
||||
break;
|
||||
case FactoryNeeds.NeedStackerInputLoad:
|
||||
solutionAction += DeliveryStackerInputLoad;
|
||||
case FactoryNeeds.GenerateLoad:
|
||||
GenerateLoad();
|
||||
break;
|
||||
}
|
||||
}
|
||||
solutionAction?.Invoke();
|
||||
solutionAction = null;
|
||||
needs.Clear();
|
||||
}
|
||||
|
||||
private void AGVNeedsSolutioning(List<FactoryNeeds> list)
|
||||
{
|
||||
foreach (var needs in list)
|
||||
{
|
||||
switch (needs)
|
||||
{
|
||||
case FactoryNeeds.GenerateAGV:
|
||||
GenerateAGV();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void StackerStacking()
|
||||
{
|
||||
foreach (var stacker in stackerCranes)
|
||||
{
|
||||
if (stackingReadys.Add(stacker) && !stacker.inputPort.isEmpty)
|
||||
{
|
||||
Debug.Log("Stacker Stacking");
|
||||
stacker.onCompleteTask += OnStackerStackingComplete;
|
||||
stacker.AddTask(new InputTask());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStackerStackingComplete(StackerCrane crane)
|
||||
{
|
||||
stackingReadys.Remove(crane);
|
||||
crane.onCompleteTask -= OnStackerStackingComplete;
|
||||
resourceNeedsChecker.Scanning();
|
||||
stackerNeedsChecker.Scanning();
|
||||
}
|
||||
private void OnStackerInputLoad(StackerCrane stacker)
|
||||
{
|
||||
Debug.Log($"Stacker {stacker.name} is On Input Load");
|
||||
stacker.inputPort.onLoadEvent -= () => OnStackerInputLoad(stacker);
|
||||
}
|
||||
|
||||
|
||||
private void DeliveryStackerInputLoad()
|
||||
{
|
||||
if (!agvManager.TryGetIdleAGV(out var agvWorker))
|
||||
@@ -122,6 +193,14 @@ namespace XED
|
||||
agvWorker.AddAction(new AGVLoadAction(generatePort));
|
||||
agvWorker.AddAction(new AGVMoveAction(inputLoadPath));
|
||||
agvWorker.AddAction(new AGVUnloadAction(inputPortNode.loader));
|
||||
agvWorker.onCompleteTask += OnAGVIdle;
|
||||
}
|
||||
|
||||
void OnAGVIdle(AGV worker)
|
||||
{
|
||||
Debug.Log($"{worker.name} is On Enter idle");
|
||||
stackerNeedsChecker.Scanning();
|
||||
worker.onCompleteTask -= OnAGVIdle;
|
||||
}
|
||||
|
||||
private void GenerateLoad()
|
||||
@@ -141,34 +220,5 @@ namespace XED
|
||||
var newAGV = agvManager.CreateEmptyAGV();
|
||||
newAGV.ForceSet(startNode);
|
||||
}
|
||||
|
||||
void CheckStackerSpace()
|
||||
{
|
||||
if (stackerCranes.Sum(sc => sc.cells.Count()) == loads.Count)
|
||||
return;
|
||||
|
||||
foreach (var stacker in stackerCranes)
|
||||
{
|
||||
if (stacker.hasEmptyCell)
|
||||
{
|
||||
Debug.Log($"Need Stacker Load");
|
||||
needs.Add(FactoryNeeds.NeedLoad);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckAGVCount()
|
||||
{
|
||||
Debug.Log($"CheckAGVCount");
|
||||
if (maxAGVCount > agvManager.agvs.Count)
|
||||
{
|
||||
needs.Add(FactoryNeeds.NeedAGV);
|
||||
}
|
||||
else
|
||||
{
|
||||
scanningAction -= CheckAGVCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user