1104
This commit is contained in:
72
Assets/Scripts/Simulator/Components/RackComponent.cs
Normal file
72
Assets/Scripts/Simulator/Components/RackComponent.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using Simulator.Model;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UVC.Data.Core;
|
||||
|
||||
namespace Simulator.Data {
|
||||
public class RackComponent : ComponentBase
|
||||
{
|
||||
public GameObject cellPrefab;
|
||||
public RackDataClass rackData;
|
||||
|
||||
public Dictionary<(int x,int y, int z),CellComponent> cellComponents=new Dictionary<(int x, int y, int z), CellComponent>();
|
||||
public List<GameObject> entitys=new List<GameObject>();
|
||||
|
||||
public void SetComponent(RackDataClass data)
|
||||
{
|
||||
this.data = data;
|
||||
rackData= data;
|
||||
SpawnCell(data.rack_layout,false);
|
||||
}
|
||||
|
||||
public override void GetModelData(DataObject modelData)
|
||||
{
|
||||
var datas = modelData.GetDataObject("data");
|
||||
var entityid = datas.GetString("entity_id");
|
||||
List<string> entityids = new List<string>() { entityid };
|
||||
var coordinates = datas.GetDataObject("coordinates");
|
||||
var x = (int)coordinates.GetInt("x");
|
||||
var y = (int)coordinates.GetInt("y");
|
||||
var z = (int)coordinates.GetInt("z");
|
||||
var entity=EntityManager.Instance.GetEntities(entityids,this);
|
||||
entity[0].transform.SetParent(cellComponents[(x, z, y)].Socket.transform);
|
||||
entity[0].transform.localPosition = new Vector3(0, 0, 0);
|
||||
entitys.Add(entity[0].gameObject);
|
||||
}
|
||||
|
||||
public void SpawnCell(rack_layout layout,bool asrs)
|
||||
{
|
||||
Vector3 center = new Vector3(layout.x * layout.x_length / 2f, 0f, layout.y * layout.y_length / 2f);
|
||||
transform.position = center;
|
||||
|
||||
for (int z = 0; z < layout.z; z++)
|
||||
{
|
||||
for(int y=0;y<layout.y; y++)
|
||||
{
|
||||
for(int x=0;x<layout.x; x++)
|
||||
{
|
||||
var cell = Instantiate(cellPrefab);
|
||||
cell.transform.localScale=new Vector3(layout.x_length, layout.z_length, layout.y_length);
|
||||
cell.transform.parent = this.transform;
|
||||
cell.transform.position = new Vector3(layout.x_length * x*0.55f, layout.z_length * z * 0.55f, layout.y_length * y * 0.55f);
|
||||
cellComponents.Add((x, z, y), cell.GetComponent<CellComponent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (asrs)
|
||||
{
|
||||
var pickcell = Instantiate(cellPrefab);
|
||||
pickcell.transform.localScale = new Vector3(layout.x_length, layout.z_length, layout.y_length);
|
||||
pickcell.transform.parent = this.transform;
|
||||
pickcell.transform.position = new Vector3(layout.x_length * -0.55f, layout.z_length * 0, layout.y_length * 0);
|
||||
cellComponents.Add((-1, 0, 0), pickcell.GetComponent<CellComponent>());
|
||||
var dropcell = Instantiate(cellPrefab);
|
||||
dropcell.transform.localScale = new Vector3(layout.x_length, layout.z_length, layout.y_length);
|
||||
dropcell.transform.parent = this.transform;
|
||||
dropcell.transform.position = new Vector3(layout.x_length * (layout.x+ 0.55f), layout.z_length * 0, layout.y_length * 0);
|
||||
cellComponents.Add(((int)(layout.x + 1), 0, 0), dropcell.GetComponent<CellComponent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user