99 lines
3.3 KiB
C#
99 lines
3.3 KiB
C#
using EasyInject.Attributes;
|
|
using System.ComponentModel;
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 标准输送线设备
|
|
/// </summary>
|
|
[GameObjectBean(ENameType.GameObjectName)]
|
|
public class ConveyorDevice : AbstractConveyorDevice
|
|
{
|
|
[Autowired]
|
|
private readonly ContainersManage containerManage;
|
|
[SerializeField]
|
|
[Header("是agv交互位置")]
|
|
private bool isAgvInteraction;
|
|
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (string.IsNullOrEmpty(conveyorData.containerCode))
|
|
{
|
|
return;
|
|
}
|
|
//存在容器号。同时忽略执行中的,当设备有货有容器号且待机的托盘移动到当前设备
|
|
if( conveyorData.mode == 3 && conveyorData.move % 2 == 1)
|
|
{
|
|
//获取场景中的容器
|
|
Container container = containerManage.GetContainerByCode(conveyorData.containerCode);
|
|
|
|
if (container != null)
|
|
{
|
|
//设置图层
|
|
SetLayer(container);
|
|
//如果托盘的终点不是当前位置,更改容器目标点坐标
|
|
if (!container.CheckAgentPosition(ContainerParkingPosition))
|
|
{
|
|
//Debug.LogWarning(string.Format("输送线【{0}】停盘位置 【{1}】",this.name, ContainerParkingPosition));
|
|
container.ToTarget(ContainerParkingPosition);
|
|
}
|
|
}
|
|
}
|
|
//待机有货的时候
|
|
if (conveyorData.mode == 2 && conveyorData.move % 2 == 1 && !string.IsNullOrEmpty(conveyorData.containerCode))
|
|
{
|
|
//获取场景中的容器
|
|
Container container = containerManage.GetContainerByCode(conveyorData.containerCode);
|
|
|
|
|
|
if (container == null)
|
|
{
|
|
|
|
|
|
//到这一步也就是说这个条码托盘未被加载到场景,这种情况属于初始化才会出现
|
|
ContainerEntity entity = new();
|
|
entity.containerCode = conveyorData.containerCode;
|
|
entity.containerType = conveyorData.containerType;
|
|
entity.isEmpty = conveyorData.isEmpty;
|
|
//containerManage.CreateContainer(ContainerParkingPosition, entity);
|
|
}
|
|
else
|
|
{
|
|
//如果托盘的终点不是当前位置,更改容器目标点坐标
|
|
if (!container.CheckAgentPosition(ContainerParkingPosition))
|
|
{
|
|
//Debug.LogWarning(string.Format("输送线【{0}】停盘位置 【{1}】", this.name, ContainerParkingPosition));
|
|
container.ToTarget(ContainerParkingPosition);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
public override void ProcessCompleted()
|
|
{
|
|
//流程完成后触发,用来作位置的初始化操作
|
|
Container container = containerManage.GetContainerByCode(conveyorData.containerCode);
|
|
if(container == null)
|
|
{
|
|
//到这一步也就是说这个条码托盘未被加载到场景,这种情况属于初始化才会出现
|
|
ContainerEntity entity = new();
|
|
entity.containerCode = conveyorData.containerCode;
|
|
entity.containerType = conveyorData.containerType;
|
|
entity.isEmpty = conveyorData.isEmpty;
|
|
containerManage.CreateContainer(ContainerParkingPosition, entity,gameObject.layer);
|
|
}
|
|
|
|
}
|
|
private void SetLayer(Container container)
|
|
{
|
|
foreach(var item in container.GetComponentsInChildren<Transform>())
|
|
{
|
|
item.gameObject.layer = gameObject.layer;
|
|
}
|
|
}
|
|
|
|
}
|