155 lines
5.4 KiB
C#
155 lines
5.4 KiB
C#
using DefaultNamespace;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using static UnityEngine.EventSystems.EventTrigger;
|
|
|
|
public class Palletizertent : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 设备id
|
|
/// </summary>
|
|
public string ID;
|
|
/// <summary>
|
|
/// 速度
|
|
/// </summary>
|
|
public float Speed = 3.5f;
|
|
[Header("码垛机手臂")]
|
|
public GameObject Armobj;
|
|
[Header("需要判断位置的箱子")]
|
|
public Transform Haveabox;
|
|
public void Stacking(Dpmequipment cmequipment)
|
|
{
|
|
if (cmequipment.TaskNumber != null)
|
|
{
|
|
if (cmequipment.boxesNumber == "1" && cmequipment.UpperInPlace == "True")
|
|
{
|
|
Suitcase();
|
|
}
|
|
else if (cmequipment.boxesNumber == "0" && cmequipment.DownInPlace == "True")
|
|
{
|
|
Stow();
|
|
}
|
|
else if(cmequipment.boxesNumber == "0"&&cmequipment.MiddleInPlace == "True")
|
|
{
|
|
Centreposition();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("没有条件");
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 中到位操作
|
|
/// </summary>
|
|
private void Centreposition()
|
|
{
|
|
if (Armobj.transform.childCount > 0 && Haveabox.childCount > 0)
|
|
{
|
|
GameObject box = Armobj.transform.GetChild(0).gameObject;
|
|
GameObject box2 = Haveabox.transform.GetChild(0).gameObject;
|
|
if (box != null && box2)
|
|
{
|
|
box.transform.SetParent(null);
|
|
box2.transform.SetParent(null);
|
|
Vector3 transform = box2.transform.position;
|
|
box2.transform.position = box.transform.position;
|
|
box.transform.position = transform;
|
|
box2.transform.SetParent(box.transform);
|
|
if (box.GetComponent<BoxCollider>() != null)
|
|
{
|
|
BoxCollider box3 = box.GetComponent<BoxCollider>();
|
|
box3.center = new Vector3(0, 0, 0);
|
|
//Debug.Log("把碰撞体给到箱子中心");
|
|
box.transform.SetParent(Haveabox.transform);
|
|
Armobj.transform.DOMoveY(Armobj.transform.position.y - 0.23f, 0.2f).SetEase(Ease.InOutQuad);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提箱操作
|
|
/// </summary>
|
|
/// <param name="cmequipment"></param>
|
|
public void Suitcase()
|
|
{
|
|
if (Haveabox.transform.GetChild(0).childCount > 0 && Armobj.transform.childCount == 0)
|
|
{
|
|
GameObject box = Haveabox.GetChild(0).GetChild(0).gameObject;
|
|
if (box != null)
|
|
{
|
|
box.transform.SetParent(null);
|
|
Armobj.transform.DOMoveY(Armobj.transform.position.y + 0.2f, 0.2f).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
box.transform.SetParent(Armobj.transform);
|
|
});
|
|
}
|
|
}
|
|
else if (Haveabox.childCount == 1)
|
|
{
|
|
GameObject box = Haveabox.transform.GetChild(0).gameObject;
|
|
if (box != null)
|
|
{
|
|
Armobj.transform.DOMoveY(Armobj.transform.position.y - 1.03f, 0.5f).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
box.transform.SetParent(Armobj.transform);
|
|
Armobj.transform.DOMoveY(Armobj.transform.position.y + 1.23f, 0.6f).SetEase(Ease.InOutQuad);
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("提箱子啥也不是");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 放下箱子操作
|
|
/// </summary>
|
|
public void Stow()
|
|
{
|
|
if (Armobj.transform.childCount > 0 && Haveabox.childCount == 0)
|
|
{
|
|
Armobj.transform.DOMoveY(Armobj.transform.position.y - 1.23f, 0.5f).SetEase(Ease.InOutQuad).OnComplete(() =>
|
|
{
|
|
if (Armobj.transform.childCount > 0)
|
|
{
|
|
GameObject box = Armobj.transform.GetChild(0).gameObject;
|
|
box.transform.SetParent(Haveabox);
|
|
Armobj.transform.DOMoveY(Armobj.transform.position.y + 1.03f, 0.4f).SetEase(Ease.InOutQuad);
|
|
|
|
}
|
|
});
|
|
}
|
|
//else if (Armobj.transform.childCount > 0 && Haveabox.childCount > 0)
|
|
//{
|
|
// GameObject box = Armobj.transform.GetChild(0).gameObject;
|
|
// GameObject box2 = Haveabox.transform.GetChild(0).gameObject;
|
|
// if (box != null && box2)
|
|
// {
|
|
// box.transform.SetParent(null);
|
|
// box2.transform.SetParent(null);
|
|
// Vector3 transform = box2.transform.position;
|
|
// box2.transform.position = box.transform.position;
|
|
// box.transform.position = transform;
|
|
// box2.transform.SetParent(box.transform);
|
|
// if (box.GetComponent<BoxCollider>() != null)
|
|
// {
|
|
// BoxCollider box3 = box.GetComponent<BoxCollider>();
|
|
// box3.center = new Vector3(0, 0, 0);
|
|
// //Debug.Log("把碰撞体给到箱子中心");
|
|
// box.transform.SetParent(Haveabox.transform);
|
|
// Armobj.transform.DOMoveY(Armobj.transform.position.y - 0.23f, 0.2f).SetEase(Ease.InOutQuad);
|
|
// }
|
|
// }
|
|
//}
|
|
else
|
|
{
|
|
Debug.Log("放箱子啥也不是");
|
|
}
|
|
}
|
|
}
|