1104
This commit is contained in:
49
Assets/Scripts/Simulator/Components/ASRS/ASRSComponent.cs
Normal file
49
Assets/Scripts/Simulator/Components/ASRS/ASRSComponent.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Gpm.Ui.Sample;
|
||||
using Simulator.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEngine;
|
||||
using UVC.Data.Core;
|
||||
|
||||
public class ASRSComponent : ComponentBase
|
||||
{
|
||||
ASRSDataClass asrsData = new ASRSDataClass();
|
||||
public RackComponent rack;
|
||||
public StackerCrane stacker;
|
||||
|
||||
public void SetComponent(ASRSDataClass asrsData)
|
||||
{
|
||||
this.asrsData = asrsData;
|
||||
data = asrsData;
|
||||
SetRack(asrsData.asrs_layout);
|
||||
SetStackerCrane(asrsData.asrs_layout);
|
||||
}
|
||||
|
||||
public override void GetModelData(DataObject modelData)
|
||||
{
|
||||
var name = modelData.GetString("event_name");
|
||||
if (string.Equals(name,"moving"))
|
||||
{
|
||||
stacker.SetTargetPosition(modelData,rack);
|
||||
}
|
||||
if (string.Equals(name, "fork_operation"))
|
||||
{
|
||||
stacker.SetForkPosition(modelData,rack);
|
||||
}
|
||||
if (string.Equals(name, "arrived"))
|
||||
{
|
||||
rack.GetModelData(modelData);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRack(rack_layout layout)
|
||||
{
|
||||
rack.SpawnCell(layout,true);
|
||||
}
|
||||
|
||||
void SetStackerCrane(rack_layout layout)
|
||||
{
|
||||
stacker.SetPosition(layout);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38ccc9b02f283c243b1cb0e81389920f
|
||||
169
Assets/Scripts/Simulator/Components/ASRS/StackerCrane.cs
Normal file
169
Assets/Scripts/Simulator/Components/ASRS/StackerCrane.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using Simulator.Data;
|
||||
using Simulator.Data.Transport;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UVC.Data.Core;
|
||||
|
||||
public class StackerCrane : ComponentBase
|
||||
{
|
||||
[SerializeField]
|
||||
GameObject horizonObject;
|
||||
[SerializeField]
|
||||
GameObject verticalObject;
|
||||
[SerializeField]
|
||||
GameObject forkObject;
|
||||
|
||||
bool horizontalPosition = false;
|
||||
bool verticalPosition = false;
|
||||
bool forkPosition = false;
|
||||
bool operationflag = false;
|
||||
bool operationcounting = false;
|
||||
Vector3 horizontalTarget;
|
||||
Vector3 verticalTarget;
|
||||
Vector3 forkTarget;
|
||||
Vector3 horizontalStart;
|
||||
Vector3 verticalStart;
|
||||
Vector3 forkStart;
|
||||
Vector3 startposition;
|
||||
string entityId;
|
||||
float horizontalTime;
|
||||
float verticalTime;
|
||||
float forkTime;
|
||||
float ht;
|
||||
float vt;
|
||||
float ft;
|
||||
|
||||
public void SetPosition(rack_layout layout)
|
||||
{
|
||||
horizonObject.transform.localPosition = new Vector3(layout.x_length * -0.55f, layout.z_length * 0, layout.y_length * -0.5f);
|
||||
startposition = new Vector3(layout.x_length * -0.55f, layout.z_length * 0, layout.y_length * -0.5f);
|
||||
forkStart = new Vector3(0, 0, 0.3f);
|
||||
}
|
||||
public void SetTargetPosition(DataObject agvData, RackComponent rack)
|
||||
{
|
||||
var datas = agvData.GetDataObject("data");
|
||||
var crane_movement = datas.GetDataObject("crane_movement");
|
||||
horizontalTime = (float)crane_movement.GetFloat("horizontal_time");
|
||||
horizontalTime = horizontalTime / 10f;
|
||||
verticalTime = (float)crane_movement.GetFloat("vertical_time");
|
||||
verticalTime = verticalTime / 10f;
|
||||
var from = crane_movement.GetDataObject("from_position");
|
||||
var fx = (int)from.GetInt("x");
|
||||
var fy = (int)from.GetInt("y");
|
||||
var fz = (int)from.GetInt("z");
|
||||
horizontalStart = new Vector3(horizonObject.transform.position.x, 0, startposition.z);
|
||||
verticalStart = new Vector3(-0.03920534f, -0.2531985f, verticalObject.transform.position.z);
|
||||
var to = crane_movement.GetDataObject("to_position");
|
||||
var tx = (int)to.GetInt("x");
|
||||
var ty = (int)to.GetInt("y");
|
||||
var tz = (int)to.GetInt("z");
|
||||
var rackp = rack.cellComponents[(tx, tz, ty)].transform.position;
|
||||
//Debug.Log($"{tx},{ty},{tz}");
|
||||
horizontalTarget = new Vector3(rackp.x, 0, startposition.z);
|
||||
verticalTarget = new Vector3(-0.03920534f, -0.2531985f, rackp.y);
|
||||
ht = 0f;
|
||||
vt = 0f;
|
||||
horizontalPosition = true;
|
||||
verticalPosition = true;
|
||||
}
|
||||
|
||||
public void SetForkPosition(DataObject agvData, RackComponent rack)
|
||||
{
|
||||
var datas = agvData.GetDataObject("data");
|
||||
entityId = datas.GetString("entity_id");
|
||||
var operation = datas.GetString("operation");
|
||||
if (string.Equals(operation, "up"))
|
||||
{
|
||||
operationflag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
operationflag = false;
|
||||
}
|
||||
operationcounting = true;
|
||||
var timing = datas.GetDataObject("timing");
|
||||
forkTime = (float)timing.GetFloat("total");
|
||||
var position = datas.GetDataObject("position");
|
||||
var x = (int)position.GetInt("x");
|
||||
var y = (int)position.GetInt("y");
|
||||
var z = (int)position.GetInt("z");
|
||||
var rackp = rack.cellComponents[(x, z, y)].transform.position;
|
||||
ft = 0f;
|
||||
forkTarget = new Vector3(-rackp.z+startposition.x,0, 0.3f);
|
||||
Debug.Log($"t{forkTarget}");
|
||||
Debug.Log($"s{forkStart}");
|
||||
forkPosition = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (horizontalPosition)
|
||||
{
|
||||
if (horizontalTime >= 0f)
|
||||
{
|
||||
ht += Time.deltaTime / horizontalTime;
|
||||
|
||||
// 위치 업데이트
|
||||
if (ht <= 1f)
|
||||
{
|
||||
horizonObject.transform.localPosition = Vector3.Lerp(horizontalStart, horizontalTarget, ht);
|
||||
}
|
||||
else
|
||||
{
|
||||
horizonObject.transform.localPosition = horizontalTarget;
|
||||
horizontalPosition = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (verticalPosition)
|
||||
{
|
||||
if (verticalTime >= 0f)
|
||||
{
|
||||
vt += Time.deltaTime / verticalTime;
|
||||
|
||||
// 위치 업데이트
|
||||
if (vt <= 1f)
|
||||
{
|
||||
verticalObject.transform.localPosition = Vector3.Lerp(verticalStart, verticalTarget, vt);
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalObject.transform.localPosition = verticalTarget;
|
||||
verticalPosition = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (forkPosition)
|
||||
{
|
||||
if (forkTime >= 0f)
|
||||
{
|
||||
ft += Time.deltaTime / forkTime;
|
||||
// 위치 업데이트
|
||||
if (ft <= 0.5f)
|
||||
{
|
||||
forkObject.transform.localPosition = Vector3.Lerp(forkStart, forkTarget, ft);
|
||||
}
|
||||
else if (ft >= 0.5f && ft <= 1f)
|
||||
{
|
||||
if (operationcounting)
|
||||
{
|
||||
if (operationflag)
|
||||
{
|
||||
var entity = EntityManager.Instance.GetEntity(entityId,this);
|
||||
entity.transform.parent = forkObject.transform;
|
||||
entity.transform.localPosition = new Vector3(0, 0, 0);
|
||||
}
|
||||
operationcounting = false;
|
||||
}
|
||||
forkObject.transform.localPosition = Vector3.Lerp(forkTarget, forkStart, ft);
|
||||
}
|
||||
else
|
||||
{
|
||||
forkObject.transform.localPosition = forkStart;
|
||||
forkPosition = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed3ea1e82c6dfe64b8b181f304a8a0c7
|
||||
Reference in New Issue
Block a user