123 lines
4.0 KiB
C#
123 lines
4.0 KiB
C#
using EasyInject.Attributes;
|
|
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// 库存信息管理
|
|
/// </summary>
|
|
[GameObjectBean]
|
|
[AddComponentMenu("WXDC/Storage/LocationStorageManage")]
|
|
public class LocationStorageManage : MonoBehaviour,IStorageSocketDataHandle
|
|
{
|
|
[Autowired("WmsStorageWebsocket")]
|
|
private WmsStorageWebsocket wmsStorageWebsocket;
|
|
/// <summary>
|
|
/// 库位信息维护,库位信息等来源
|
|
/// </summary>
|
|
[Header("所有库位信息")]
|
|
public List<GameObject> storages = new List<GameObject> ();
|
|
|
|
[Header("所有站台列信息")]
|
|
public List<GameObject> localtionStorages = new List<GameObject>();
|
|
[Autowired]
|
|
private ContainersManage containerManage;
|
|
[Header("平库开始排")]
|
|
[SerializeField]
|
|
public int startRow = 33;
|
|
[Header("平库结束排")]
|
|
[SerializeField]
|
|
public int endRow = 80;
|
|
private void Start()
|
|
{
|
|
storages = FindObjectsWithDashInName();
|
|
storages.AddRange(localtionStorages);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据正则表达式查找名称
|
|
/// </summary>
|
|
/// <returns>符合条件的游戏对象列表</returns>
|
|
private List<GameObject> FindObjectsWithDashInName()
|
|
{
|
|
List<GameObject> result = new List<GameObject>();
|
|
// 正则表达式:匹配
|
|
Regex regex = new Regex("^\\d{2}-\\d{2}-\\d{2}$");
|
|
foreach (GameObject obj in GameObject.FindObjectsByType<GameObject>(FindObjectsSortMode.InstanceID))
|
|
{
|
|
// 1. 检查名称是否匹配正则表达式
|
|
if (regex.IsMatch(obj.name))
|
|
{
|
|
result.Add(obj);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
public GameObject GetStorageByName(string code)
|
|
{
|
|
return storages.Find(v=> string.Equals(v.name,code));
|
|
}
|
|
public GameObject GetStorageByName(int row,int cloumn,int layer)
|
|
{
|
|
string name = row.ToString("D2") + "-" + cloumn.ToString("D2") + "-" + layer.ToString("D2");
|
|
return storages.Find(v => string.Equals(v.name, name));
|
|
}
|
|
public void DataHandle(object data, object other = null)
|
|
{
|
|
LocationStorageInfo info = (LocationStorageInfo)data;
|
|
//空数据直接结束
|
|
if (info == null)
|
|
{
|
|
return;
|
|
}
|
|
//库位无锁状态处理
|
|
if(info.locked == 0)
|
|
{
|
|
//先拿到库位
|
|
GameObject storage = storages.Find(v => string.Equals(v.name, info.code));
|
|
|
|
if (storage == null)
|
|
{
|
|
return ;
|
|
}
|
|
|
|
//库位没有锁且没有条码了,场景存在容器移除
|
|
//还需要判断当前模型父组件是库位
|
|
if (string.IsNullOrEmpty(info.containerCode)){
|
|
|
|
if (storage != null)
|
|
{
|
|
//库位内,有这个模型移除
|
|
Container container = storage.GetComponentInChildren<Container>();
|
|
|
|
//移除
|
|
containerManage.RemoveContainer(container);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//如果场景存在托盘则不创建了
|
|
Container container = containerManage.GetContainerByCode(info.containerCode);
|
|
if (container != null && container.gameObject.activeSelf)
|
|
{
|
|
return;
|
|
}
|
|
int row = int.Parse(storage.name.Split("-")[0]);
|
|
ContainerEntity entity = new();
|
|
entity.location = info.code;
|
|
entity.containerCode = info.containerCode;
|
|
entity.containerType = info.containerTypeCode;
|
|
if (row >= startRow && row <= endRow)
|
|
{
|
|
containerManage.CreateContainer(new Vector3(0, -0.2472343f, 0.0006999969f), storage.transform, entity, storage.layer);
|
|
}
|
|
else
|
|
{
|
|
containerManage.CreateContainer(Vector3.zero, storage.transform, entity, storage.layer);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|