Files
XRLib/Assets/Scripts/Simulator/Components/RackComponent.cs
2025-11-04 19:02:01 +09:00

73 lines
3.4 KiB
C#

using System.Collections.Generic;
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, y, z)].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.z * layout.z_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.y_length, layout.z_length);
cell.transform.position = new Vector3(layout.x_length * x*0.55f, layout.y_length * y * 0.59f, layout.z_length * z * 0.75f);
cell.transform.parent = this.transform;
cellComponents.Add((x, y, z), cell.GetComponent<CellComponent>());
cellComponents[(x, y, z)].x = x;
cellComponents[(x, y, z)].y = y;
cellComponents[(x, y, z)].z = z;
}
}
}
if (asrs)
{
var pickcell = Instantiate(cellPrefab);
pickcell.transform.localScale = new Vector3(layout.x_length, layout.y_length, layout.z_length);
pickcell.transform.position = new Vector3(layout.x_length * -0.55f, layout.y_length * 0, layout.z_length * 0);
pickcell.transform.parent = this.transform;
cellComponents.Add((-1, 0, 0), pickcell.GetComponent<CellComponent>());
var dropcell = Instantiate(cellPrefab);
dropcell.transform.localScale = new Vector3(layout.x_length, layout.y_length, layout.z_length);
dropcell.transform.position = new Vector3(layout.x_length * (layout.x)*0.55f, layout.y_length * 0, layout.z_length * 0);
dropcell.transform.parent = this.transform;
cellComponents.Add(((int)(layout.x), 0, 0), dropcell.GetComponent<CellComponent>());
}
}
}
}