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