75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using EasyInject.Attributes;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
/// <summary>
|
||
/// 设备解析服务
|
||
/// </summary>
|
||
[Component("DeviceParseService")]
|
||
public class DeviceParseService
|
||
{
|
||
[Autowired("LocationStorageManage")]
|
||
private LocationStorageManage storageManage;
|
||
|
||
/// <summary>
|
||
/// 根据设备号解析所在场景坐标
|
||
/// </summary>
|
||
/// <param name="device"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="System.Exception"></exception>
|
||
public Vector3 PositionByDevice(string device)
|
||
{
|
||
if (string.IsNullOrEmpty(device))
|
||
{
|
||
throw new System.Exception("解析设备坐标异常,设备号未传递");
|
||
}
|
||
//带横杠就是库位
|
||
|
||
if(device.Contains("-"))
|
||
{
|
||
if(storageManage == null)
|
||
{
|
||
storageManage = ApplicationBoot.Instance.GetBean<LocationStorageManage>();
|
||
}
|
||
GameObject storage = storageManage.storages.Find(v => v.name == device);
|
||
if (storage != null)
|
||
{
|
||
return storage.transform.position;
|
||
}
|
||
throw new System.Exception("解析设备坐标异常,场景不存在该设备 :"+device);
|
||
}
|
||
|
||
List<IDevice> list = ApplicationBoot.Instance.GetBeans<IDevice>();
|
||
IDevice currentDevice = list.Find(v => v.DeviceCode == device);
|
||
if (currentDevice != null)
|
||
{
|
||
return currentDevice.Transform.position;
|
||
}
|
||
|
||
throw new System.Exception("解析设备坐标异常");
|
||
}
|
||
/// <summary>
|
||
/// 根据设备名在场景搜索
|
||
/// </summary>
|
||
/// <param name="device"></param>
|
||
/// <returns></returns>
|
||
public GameObject GameObjectByDevice(string device)
|
||
{
|
||
//是库位
|
||
if(device.Contains("-"))
|
||
{
|
||
GameObject obj = storageManage.storages.Find(v => string.Equals(device, v.name));
|
||
if (obj != null)
|
||
{
|
||
return obj;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ConveyorDevice conveyor = ApplicationBoot.Instance.GetBean<ConveyorDevice>(device);
|
||
return conveyor.Position;
|
||
}
|
||
throw new Exception(string.Format("未在找到设备【{0}】", device));
|
||
}
|
||
}
|